count number of rows

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
1,930
Office Version
  1. 365
Platform
  1. Windows
I am using this code to determine the last row and to delete data.

How can I use something like this to count how many rows there are from A3 down and then check another row (like B3) down to see if it has the same number of fields with data in it?

If I have 10 rows in column A starting from A3 down I want to check B3 down to ensure it has the same number. There should be the same number - if there isnt that means the user did not fill in all the required data and I want to trigger a message box telling them to check.

Thanks

Code:
Dim lr1 As Long
    
        'Clear existing data if any
        lr1 = Sheets("Assemblies").Cells(Rows.Count, "A").End(xlUp).Row
        If lr1 > 2 Then Sheets("Assemblies").Range("A3:T" & lr1).ClearContents
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Phuoc

Well-known Member
Joined
Apr 29, 2016
Messages
532
Office Version
  1. 2016
Try this

VBA Code:
Public Sub Test()
Dim lr1 As Long, lr2 As Long
    
    With Sheets("Assemblies")
        lr1 = .Cells(Rows.Count, "A").End(xlUp).Row
        lr2 = .Cells(Rows.Count, "B").End(xlUp).Row
        If lr1 <> lr2 Then MsgBox "The last row of the 2 columns is not the same"
    End With
End Sub
 
Solution
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,151,822
Messages
5,766,648
Members
425,366
Latest member
Mau15092000

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
Top