Compare ranges

jtodd

Board Regular
Joined
Aug 4, 2014
Messages
194
HI
I have 2 sets of data I2:I13 and J2:J13
What I want to do is compare the cells and if the cell in I2 is > J2 then a message.
This would be relative ie would compare all cells - I3>J3 ect
This is what I have
Private Sub Worksheet_Change(ByVal Target As Range)

If Range("I2") > Range("j2") Then
MsgBox "Resource needed exceeds resource available "
End If
If Range("I3") > Range("j3") Then
'MsgBox "Resource needed exceeds resource available "

End If

End Sub

Which works ok but would mean that I will have to write code for each cell.
Must be an easer way!!

Any help would be apriciated
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Try:
Code:
Sub Macro1()

    Dim x   As Long
    
    For x = 2 To 13
        With Cells(x, 9)
            If .Value > .Offset(, 1).Value Then MsgBox "Resource needed exceeds resource available", vbExclamation, "Not Enough Resources"
        End With
    Next x

End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,743
Messages
6,126,609
Members
449,321
Latest member
syzer

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