Find Last Row and select range

nkustura

New Member
Joined
Jun 20, 2011
Messages
21
Hi,

I need some help with a macro. I need a macro that will find last row/cell on a spreadsheet that has data and select a range from first row to the last row with data that was just found.

All help is greatly appreciated.

Thanks,
Nermina
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Thanks for the instant resposne.

Will this macro also select rows that might not have data but might have some formating?

Thanks,
Nermina
 
Upvote 0
I don't really need to select rows with formating only. I just need to select rows that have data in them.

Another question that tags onto this one is: After I find last row, I need to insert "product" i every cell in column A for that range of first row to last row with data. Ex. if last row happens to be 237 then I need to have work "product in cells A1 thru A237.

Thank you so much for your help, I really appreciate it.

-nermina
 
Upvote 0
Does this work as expected?

Code:
Sub Test2()
Dim LR As Long, LC As Long
LR = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
LC = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column
Range(Cells(1, 1), Cells(LR, LC)).Select
End Sub
 
Upvote 0
This is weird. I re-wrote the code in different workbook and it worked fine. Thank you so much for your help.
 
Upvote 0
I need to make one more tweak to this macro. Now that I know how to make it find last row with data on the spreadsheet, I need to copy value from cell B1 and paste into range (A1:LastRow with data). How can I do this?

Thanks,
Nermina
 
Upvote 0

Forum statistics

Threads
1,224,505
Messages
6,179,152
Members
452,891
Latest member
JUSTOUTOFMYREACH

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