Need Assistance Tweaking VBA (last row / column)

sparkytech

Board Regular
Joined
Mar 6, 2018
Messages
96
Office Version
  1. 365
  2. 2019
I have the following generic code to find the bottom row and last columns. I need to change this to find the last row containing data, and to specify specific columns instead of all. Can someone guide me? Thanks!

VBA Code:
BotR = MasterWS.Cells.Find(What:="*", After:=Range("A1"), LookAt:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).Row

LastC = MasterWS.Cells.Find(What:="*", After:=Range("A1"), LookAt:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False).Column
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
this will give you the lastrow with data in it on the sheet and the lastcolumn with data in it

Excel Formula:
lrow = ActiveSheet.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

lcol = ActiveSheet.Cells.Find("*", SearchOrder:=xlBycolumns, SearchDirection:=xlPrevious).column

when you say specify specific columns what do you mean? In your search range or return the specific column that the last row of data is in?
 
Upvote 0
this will give you the lastrow with data in it on the sheet and the lastcolumn with data in it

Excel Formula:
lrow = ActiveSheet.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

lcol = ActiveSheet.Cells.Find("*", SearchOrder:=xlBycolumns, SearchDirection:=xlPrevious).column

when you say specify specific columns what do you mean? In your search range or return the specific column that the last row of data is in?
Thanks for the code! What I meant by specific columns, is that I want it to only search column A to Y.
 
Upvote 0
Where your code has "Cells" replace it with the range ie

Excel Formula:
lrow = ActiveSheet.Range("A:Y").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
 
Upvote 0

Forum statistics

Threads
1,215,781
Messages
6,126,868
Members
449,345
Latest member
CharlieDP

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