Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default "Else IF" syntax used in an Excel VB Macro

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default "Else IF" syntax used in an Excel VB Macro

Try

IF Range("A18") 0 Then
Range("A19").Select
Else
Range("A18").Select
End If


--

HTH

RP

"Gids_w" wrote in message
...
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.



  #3   Report Post  
Posted to microsoft.public.excel.programming
RWN RWN is offline
external usenet poster
 
Posts: 104
Default "Else IF" syntax used in an Excel VB Macro

"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.
--
Regards;
Rob
------------------------------------------------------------------------
"Gids_w" wrote in message
...
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.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default "Else IF" syntax used in an Excel VB Macro


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

--
mackerm
-----------------------------------------------------------------------
mackerma's Profile: http://www.excelforum.com/member.php...fo&userid=1534
View this thread: http://www.excelforum.com/showthread.php?threadid=27054

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
correct syntax for nesting "if", "and", and "vlookup"....if possib Christine Excel Worksheet Functions 4 January 2nd 09 10:43 PM
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
Syntax to "OR" 3 "ISERROR" conditions Mike K Excel Worksheet Functions 6 July 22nd 06 04:18 PM
Macro to concatenate into "B1" B2 thru B"x" based on new data in "Col A" Dennis Excel Discussion (Misc queries) 0 July 17th 06 02:38 PM
what is syntax for if(between range of dates,"Q1","Q2")? TLB Excel Worksheet Functions 3 December 6th 05 05:19 PM


All times are GMT +1. The time now is 05:17 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"