IF THEN ELSE in VBA
One way:
Public Sub FieldTip()
Select Case ActiveCell.Address(False, False)
Case "M3"
Range("S8").Value = Range("K57").Value
Case "M5"
Range("S8").Value = Range("K58").Value
Case Else
Range("S8").ClearContents
End Select
End Sub
Note: Change
Range("S8").ClearContents
to
Range("S8").Value = " "
if you really want the space character inserted.
In article ,
CCManager wrote:
What I am trying to do:
If the user has cell M3 selected, then change cell S8 to show the data
in cell K57. If the user has cell M5 selected, change cell S8 to show
the data in cell K58...and so on.
Here is what I have that is not working.
Sub FieldTip()
If ActiveCell.Value = ("M3") Then Range("S8").Value = ("K57")
Else: If ActiveCell.Value = ("M5") Then Range("S8").Value = ("K58")
Else: Range("S8").Value = " "
End If
End Sub
Any help would be greatly appreciated.
|