vba code that checks one cell value against another.

danbates

Active Member
Joined
Oct 8, 2017
Messages
377
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
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
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
 
Upvote 0

Forum statistics

Threads
1,214,970
Messages
6,122,514
Members
449,088
Latest member
RandomExceller01

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