Forum Discussion
sandeep singh
Oct 05, 2018Copper Contributor
vba -excel -how to check and compare cell value against next cell's value in same column
Private Sub CommandButton1_Click()
Dim i As Integer, j As Integer, temp As Integer, rng As Range
Set rng = Range("A1").CurrentRegion
For i = 1 To rng.Count
For j = i + 1 To rng.Count
If rng.Cells(j) < rng.Cells(i) Then
MsgBox "Alert -Entry in row is Less Than Previous Cell !!"
Exit Sub
End If
Next j
Next i
End Sub
I tried bit of coding but it does not work -I need to check value of cell while i enter data in cell
pls see attached file.
hope you can work something out of it.
thanks..
4 Replies
- Lorenzo KimBronze Contributor
- sandeep singhCopper Contributor
Thanks a lot for sharing this code
Lorenzo Kim wrote:pls see attached file.
hope you can work something out of it.
thanks..
- Lorenzo KimBronze Contributorglad to be of help..
- Lorenzo KimBronze Contributor
I think this requires a Worksheet_Change sub...
or Data validation