count number of rows

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,340
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

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
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
 
Upvote 0
Solution

Forum statistics

Threads
1,214,655
Messages
6,120,760
Members
448,991
Latest member
Hanakoro

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