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
- Aug 02, 2022
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.
OliverScheurich
Aug 02, 2022Gold 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.