vba code that checks one cell value against another.

danbates

Active Member
Joined
Oct 8, 2017
Messages
343
Office Version
  1. 2016
Platform
  1. Windows
Hi,

Please can someone help me?

I would like a vba code that checks if the cell value in column 'I' is less than the value in column 'D'.
If it is less then it carries on but if its more then I'd like a message box to say this cannot happen.

Any help would be much appreciated.

Kind Regards
Dan
 

Some videos you may like

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
17,388
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Code:
Sub CheckIagainstD()
Dim R As Range, V As Variant, i As Long, BadCells As String
Set R = Range("D1:I" & Cells(Rows.Count, "I").End(xlUp).Row)
V = R.Value
For i = 1 To UBound(V, 1)
    If IsNumeric(V(i, 6)) Then
        If V(i, 6) >= V(i, 1) Then BadCells = BadCells & ", " & R(i, 6).Address(0, 0)
    End If
Next i
If BadCells <> "" Then
    MsgBox "The following cells in col I are more than or equal to their counterpart cells in col D - this cannot happen!" & vbNewLine & Mid(BadCells, 3, Len(BadCells))
End If
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,122,476
Messages
5,596,373
Members
414,063
Latest member
N_Bates

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