1

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

Community
  • 1
  • 1
user2365820
  • 11
  • 1
  • 2
  • Kindly 'close' the questions by marking correct answers. This is what people here like when helping others. It will help ppl with same problem to identify the correct solution :) – Santosh May 28 '13 at 01:12

2 Answers2

1

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
Robert Mearns
  • 11,796
  • 3
  • 38
  • 42
0

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
Community
  • 1
  • 1
Santosh
  • 12,175
  • 4
  • 41
  • 72