Find last row with data

parry

MrExcel MVP
Joined
Aug 20, 2002
Messages
3,355
Hi, Im sure Ive seen something here to quickly find the last row with data in a column but cant see it now.

I have the following code ....
dim rngBank as range
For Each rngBank In ThisWorkbook.Worksheets("sheet1").Range("L:L")

Rather than range L:L I only want from L1 until last row with data in it.

I have previously assigned a variable to Selection.End(xlDown).Select and then found row for this then gone back to the top but I have seen people select the last row (65000+) in a statement that does this in one line.

Any ideas?

Thanks
Parry
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Thanks Juan! That was it. Unfortunately Im doing something wrong because I keep getting a runtime "error 1004:application-defined or object-defined error" on the ForEach line.

Dim rngBank As Range
Dim strBank As String
Dim rngBankLast As Range

Range("l1").Select
Set rngBankLast = Range("L65536").End(xlUp)
For Each rngBank In ThisWorkbook.Worksheets("sheet1").Range([rngBankLast])
strBank = rngBank.Value
AddZero strBank, 2
rngBank.Value = strBank
Next

Can you help?
Thanks
Parry
 
Upvote 0
Oops also forgot to say that when doing a debug the Set line has a value of 2 even though the last range is row 38.

Maybe thats why its coming up with an error because the range is only one row? Dont know.

Thanks again
Parry
 
Upvote 0
parry,

not sure if this is what you want or not, but this is the program I got to find and select only the data in a specified Column. No matter how many rows you have, it always finds the top and bottom and selects everything in between.... so you may have to modify this a bit.....hope this helps:

Sub Selected_Range()

Dim wsSheet As Worksheet
Dim rnArea As Range

Sheets("Sheet2").Select

Set wsSheet = ThisWorkbook.Worksheets("Sheet2")

With wsSheet
Set rnArea = .Range(.Range("D3"), Range("D" & .Range("D65536").End(xlUp).Row))
End With

rnArea.Select

End Sub
 
Upvote 0

Forum statistics

Threads
1,222,404
Messages
6,165,855
Members
451,987
Latest member
Johnzdz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top