Reputation: 11
I'm trying to figure out VBA and Excel and I've ran into some problems. I'm trying to select a range, and depending on if another column(P) is empty, I'll choose either column N or M to select.
Basically I've tried something like this without success.
IF(P7="",Range("N7").Select , Range("M7").Select)
So in pseudo code:
IF P7 is empty DO N7.Select ELSE M7.Select
I Appreciate any help, since I can't find anything about this!
-P
Upvotes: 1
Views: 5708
Reputation: 12353
Using Select case Statement can be done as below. Select should be avoided
retVal = Range("P7").Value
Select Case retVal
Case Is = vbNullString
Range("N7").Select
Case Else
Range("M7").Select
End Select
Upvotes: 0
Reputation: 11986
The syntax of the IF statement is different between the Excel function and the VBA code
Sub MySelect()
If Range("P7") = "" Then
Range("N7").Select
Else
Range("M7").Select
End If
End Sub
Upvotes: 1