"Else IF" syntax used in an Excel VB Macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

From a macro I want it to read the contents of a cell, and from that the
macro decides which cell to select.

There is a limited range of variables, so I was thinking about doing it with
something like an Else If statement, but not sure if this is possible;

Eg:
IF A1=1, select B1, if not leave cell unchanged
Else IF A1=2 select B2 etc....

I need to know the syntax for doing something like this I have tried
=IF("A18" > 0,Range("A19").Select, Range("A18").Select)"
but get an error.

If anybody could tell me where I'm going wrong, show me a better way of
doing this i would be most greatful, thanks in advance.

G.
 
Try

IF Range("A18") > 0 Then
Range("A19").Select
Else
Range("A18").Select
End If
 
"Simple" ex
If Whatever = 1 then
do something (if "Whatever" does equal 1)
Else
something else (if "Whatever" is not equal 1)
End If

Try the help in VBA.
 
Consider using a select case statement, it might be easier:

Val=Range("A1")
Select Case Val
Case 1
Range("B1")=1 '(or Range("B1").Select )
Case 2
Range("B2")=1 '(or Range("B2").Select )
etc.

Check out the VB help for more details
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top