Marsdon
New Member
Hi Guys
I have an problem in looping the code. I have two ranges (G and H) which contains From and To dates. And my requirement here is To Date should not be less than From date. IF SO it there should be msg Box Saying TO Date is lesser than from date. And it should clear the data in that particular cell. In the same way I have to do it for Range G9 to G 26. I have created a code for a single cells . But I want the same to be repeated the below rows. I feel there should be looping done but I dont know how to loop the same.
I have an problem in looping the code. I have two ranges (G and H) which contains From and To dates. And my requirement here is To Date should not be less than From date. IF SO it there should be msg Box Saying TO Date is lesser than from date. And it should clear the data in that particular cell. In the same way I have to do it for Range G9 to G 26. I have created a code for a single cells . But I want the same to be repeated the below rows. I feel there should be looping done but I dont know how to loop the same.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("G9") < Range("F9") Then
MsgBox "Please Change the Date"
Range("G9") = Range("F9")
Range("F9").Select
End If
End Sub
Last edited by a moderator: