ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Find the last Row in a Range (https://www.excelbanter.com/excel-programming/307408-find-last-row-range.html)

TK

Find the last Row in a Range
 
Trying to write to the last row in a range. The following code works down to
( The next line fails ....
Thanks:


Private Function FindLastRow()
Dim R As Long
R = 2
Do While R < 65536 And Len(Cells(R, 11).Text) 0
R = R + 1
Loop
FindLastRow = R
End Function

Private Sub ListBox1_Click()
Lastrow = FindLastRow - 1
MsgBox Lastrow
Sheet1.Range("k1").Value = UserForm1.ListBox1.Value

( The next line fails - how should it be written?)
Sheet1.Range("kLastrow").Value = UserForm1.ListBox1.Value

End Sub


Tom Ogilvy

Find the last Row in a Range
 
Sheet1.Range("k" & Lastrow).Value = UserForm1.ListBox1.Value


you can also get the lastrow with

lastrow = cells(rows.count,11).End(xlup).row
--
Regards,
Tom Ogilvy



"TK" wrote in message
...
Trying to write to the last row in a range. The following code works down

to
( The next line fails ....
Thanks:


Private Function FindLastRow()
Dim R As Long
R = 2
Do While R < 65536 And Len(Cells(R, 11).Text) 0
R = R + 1
Loop
FindLastRow = R
End Function

Private Sub ListBox1_Click()
Lastrow = FindLastRow - 1
MsgBox Lastrow
Sheet1.Range("k1").Value = UserForm1.ListBox1.Value

( The next line fails - how should it be written?)
Sheet1.Range("kLastrow").Value = UserForm1.ListBox1.Value

End Sub




TK

Find the last Row in a Range
 


Thanks Tom


All times are GMT +1. The time now is 07:23 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com