Page 1 of 1

VBA / find last Rows -columns

Posted: Wed Feb 20, 2019 1:24 pm
by Supachok
เรียน ท่านผู้รู้

หา row สุดท้ายที่มีการใส่ข้อมูล ได้ตำแหน่ง แถว
หา column สุดท้ายที่มีการใส่ข้อมูล ได้ตำแหน่ง ค่าของ columns ปรับแต่งสุตรแล้วค่าตัวแปร C ใน Msgbox ได้columns ไม่ตรง

"MsgBox "last row : " & Rows(r).Address(False) & vbNewLine & "last col : " & Columns(c).Address"

ช่วยแนะนำที่ครับ

Code: Select all

        
r = Cells.Find(What:="*", After:=[a1], LookIn:=xlFormulas, LookAt:= _
        xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).Row
        
c = Cells.Find(What:="*", After:=[a1], LookIn:=xlFormulas, LookAt:= _
        xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False).Columns
        
        
MsgBox "last row : " & Rows(r).Address(False) & vbNewLine & "last col : " & c

Re: VBA / find last Rows -columns

Posted: Wed Feb 20, 2019 1:36 pm
by puriwutpokin
Supachok wrote: Wed Feb 20, 2019 1:24 pm เรียน ท่านผู้รู้

หา row สุดท้ายที่มีการใส่ข้อมูล ได้ตำแหน่ง แถว
หา column สุดท้ายที่มีการใส่ข้อมูล ได้ตำแหน่ง ค่าของ columns ปรับแต่งสุตรแล้วค่าตัวแปร C ใน Msgbox ได้columns ไม่ตรง

"MsgBox "last row : " & Rows(r).Address(False) & vbNewLine & "last col : " & Columns(c).Address"

ช่วยแนะนำที่ครับ

Code: Select all

        
r = Cells.Find(What:="*", After:=[a1], LookIn:=xlFormulas, LookAt:= _
        xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).Row
        
c = Cells.Find(What:="*", After:=[a1], LookIn:=xlFormulas, LookAt:= _
        xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False).Columns
        
        
MsgBox "last row : " & Rows(r).Address(False) & vbNewLine & "last col : " & c
ปรับตรงนี้ครับ

Code: Select all

r = Cells.Find(What:="*", After:=[a1], LookIn:=xlFormulas, LookAt:= _
        xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).Row
        
c = Cells.Find(What:="*", After:=[a1], LookIn:=xlFormulas, LookAt:= _
        xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False).Column    '   เอา S ออก

Re: VBA / find last Rows -columns

Posted: Wed Feb 20, 2019 2:52 pm
by Supachok
เล็กน้อยจริงๆ
แต่เพราะไม่รุ้เลยยากๆ

ขอบคุณนะครับ