Forum Discussion
Excel
Aug 02, 2022Iron Contributor
Query relates to VBA code
Hello Everyone,
I have tried VBA code with the help of IF statement with Range.
But it shows error.
What should i write ?
Please Help
Here is a attached file
Public Sub FunWithLogic() Dim rg As Range Dim cell As Range Set rg = Range("B2:B11") For Each cell In rg If cell.Value >= 90 Then MsgBox ("User is 90 or older") ElseIf cell.Value >= 20 Then MsgBox ("User is UnderAge") Else MsgBox ("Not Allowed!") End If Next cell End SubMaybe with this code.
3 Replies
- OliverScheurichGold Contributor
Public Sub FunWithLogic() Dim rg As Range Dim cell As Range Set rg = Range("B2:B11") For Each cell In rg If cell.Value >= 90 Then MsgBox ("User is 90 or older") ElseIf cell.Value >= 20 Then MsgBox ("User is UnderAge") Else MsgBox ("Not Allowed!") End If Next cell End SubMaybe with this code.
- ExcelIron ContributorThank you so much sir.
- OliverScheurichGold Contributor
You are welcome.