Thread: VBA Variable
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jacob Skaria Jacob Skaria is offline
external usenet poster
 
Posts: 8,520
Default VBA Variable

Use SELECT/CASE as below..



Select Case Range("A1")

Case "RED"
'Code for Red

Case "BLUE"
'Code for Blue

Case "GREEN"
'Code for green

Case Else
'Code if else

End Select

If this post helps click Yes
---------------
Jacob Skaria


"Newbie" wrote:

Hi,

I am trying to run a routine based on the value in a cell, for example A1
might contain RED, BLUE or GREEN.
In the VBA I would have

x = Range("A1") .value
goto x
end

RED:
'red routine here
end
BLUE:
'blue routine here
end
GREEN
'green routine here
end

...but it doesn't work, any help much appreciated.