How to find the last row with data within a range

TAPS_MikeDion

Well-known Member
Joined
Aug 14, 2009
Messages
632
Office Version
  1. 2011
Platform
  1. MacOS
Hi all,
Looks like I'm getting worse with trying to figure out VBA as I get older. LOL

All I need to do is find the last row within the range W3:AH1000 and clear the contents. I understand that I could simply use that exact range, but I have numerous sheets to have this run through so speed can be crucial. The sheets all begin with these names "A-", "D-" and "T-", which are followed by the months of the year. For example: A-JAN, A-FEB, etc. The data in the range can be numeric, text, dates, if that matters.

Thank you to anyone offering assistance!!!
 

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.
For every row that has data, is there a certain column which is required (will always have data in it)?
It is much easier to locate the last row with data if we can pinpoint a single column to check.
We can still clear multiple columns, it is just easier to identify the row if we can limit our search to a specific column.
 
Upvote 0
To find the last row with data in a specific range, you could use something like:

VBA Code:
Option Explicit
Sub Last_Row_in_Range()
    Dim LRow As Long
    LRow = Range("W3:AH1000").Find("*", , xlFormulas, , xlByRows, xlPrevious).Row
End Sub
 
Upvote 0
I don't know if this make difference in speed than clearing whole range.
Code:
Sub test()
    Dim ws As Worksheet, LR&
    Application.ScreenUpdating = falae
    For Each ws In Worksheets
        If ws.Name Like "[ADT]-*" Then
            LR = ws.[max(if(w3:ah1000<>"",row(3:1000)))]
            If LR Then ws.Range("w3:ah" & LR).ClearContents
        End If
    Next
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Hi Joe,
Yes, column A would always have data. Correction, for all three (A, D, T) it would be column B.

Thank you Kevin & Fuji. I will try these out. I greatly appreciate the help!
 
Upvote 0
Hi Joe,
Yes, column A would always have data. Correction, for all three (A, D, T) it would be column B.

Thank you Kevin & Fuji. I will try these out. I greatly appreciate the help!
Hmmm, I don't see how that would be helpful, if you are trying trying to look at the range W3:AH1000.
None of those columns are actually in that range.

So I am kind of confused by your last statement...
 
Upvote 0
Hi Joe,
I'm sorry for the delay, but last week was crazy busy. I missed words in my response, which got you confused.

"Correction, for all three sets of sheets (A-, D-, T-) it would be column B."
 
Upvote 0
Thank you all. I was able to get Fuji's code to do everything I needed. I appreciate the help!
 
Upvote 0

Forum statistics

Threads
1,225,481
Messages
6,185,246
Members
453,283
Latest member
Shortm88

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