Compare last cell values in two columns

excel_2009

Active Member
Joined
Sep 14, 2009
Messages
318
Hi Excel gurus,

I'm struggling to find a solution for this (via VBA), but is it possible to compare the last two cells in 2 columns for example, column A has 50 cells populate (A1-A50) however column B has 5 populated, is it possible to highlight this discrepancy? i.e the count of active cells in column A and B do not match thus showing a message box flagging this?

Many thanks!!
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Do you mean something like this?
VBA Code:
Sub CheckCols()

    Dim lrA As Long
    Dim lrB As Long
    
'   Find last row with data in column A
    lrA = Cells(Rows.Count, "A").End(xlUp).Row
    
'   Find last row with data in column B
    lrB = Cells(Rows.Count, "B").End(xlUp).Row
    
'   Compare values
    If lrA <> lrB Then
        MsgBox "Last row in column A is " & lrA & vbCrLf & _
                "Last row in column B is " & lrB, vbOKOnly, "LAST CELLS IN COLUMNS DON'T MATCH!"
    End If
                
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,460
Messages
6,124,949
Members
449,198
Latest member
MhammadishaqKhan

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