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

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
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,214,978
Messages
6,122,545
Members
449,089
Latest member
davidcom

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