Selecting the next blank cell on 2 columns

TM74

Board Regular
Joined
Aug 2, 2007
Messages
132
Hi,

I have a file that I create daily using VBA. In the middle of the process, some data is added into a new worksheet - columns A&B and columns D&E. On one day, the data in columns A&B could stretch to 100 rows, and the data in columns D&E could only be 2 rows. The next day the used rows could be reversed (D&E could have more used rows than A&B).

The problem that I have is that the file size is huge at the end of the process and the problem appears to be with the blank cells underneath this data. Therefore I would like to select the next blank cell in the longest column and then delete all rows underneath it (doing this manually solves the file size problem).

I can't work out any VBA to select the column with the longest amount of used rows in - can anyone help?
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Try like this

Code:
Sub Test2()
Dim LR As Long
LR = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
Rows(LR & ":" & Rows.Count).Clear
End Sub
 
Upvote 0
Hi,

I used this vba in my file today and found that it deleted the last row of data in the longest column. I also tested it in a dummy workbook and found the same problem.

Do you have any idea why? Should there be an offset in the second row of text?
 
Upvote 0
Yes, sorry

Rich (BB code):
Sub Test2()
Dim LR As Long
LR = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
Rows(LR + 1 & ":" & Rows.Count).Clear
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,834
Members
452,947
Latest member
Gerry_F

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