Forum Discussion

Excel's avatar
Excel
Iron Contributor
Aug 16, 2022
Solved

Query related to VBA code..

Hello Everyone,    I am trying to use For Each to get the range dynamically but getting a run time error . I am trying to get the Age row dynamically selected. is highlighted in yellow .   ...
  • HansVogelaar's avatar
    HansVogelaar
    Aug 25, 2022

    Excel 

    Public Sub FunWithLogic()
        ' IF logic to determine age
        If ActiveCell.Value >= 90 Then
            MsgBox ActiveCell.Offset(0, -1).Value & " is 90 or older"
        ElseIf ActiveCell.Value >= 21 Then
            MsgBox ActiveCell.Offset(0, -1).Value & " is 21 or older"
        Else
            MsgBox ActiveCell.Offset(0, -1).Value & " is not allowed!"
        End If
    End Sub

Resources