Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default create macros that uses if-then-else statments

I am new to using Macros and am looking for info on creating macros which will allow me to use if-then-else statements based on set variables and then print out the results of the conditional statement. For example: if content of cell A1=var1, print statement1, elseif content cell A1= var2 print statement2, elseif content cell A1= var3 print statement3 and so on up to var12. All content will be text If someone could point me in the right direction to learn about this it would be greatly appreciated, Thanks, Ross K.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 550
Default create macros that uses if-then-else statments

Ross,

All one line for each (be careful of word wrap):

If Range("A1") = var1 Then Worksheets("print statement 1").printout
copies:=1

John

"Ross K" wrote in message
...
I am new to using Macros and am looking for info on creating macros which

will allow me to use if-then-else statements based on set variables and then
print out the results of the conditional statement. For example: if
content of cell A1=var1, print statement1, elseif content cell A1= var2
print statement2, elseif content cell A1= var3 print statement3 and so on up
to var12. All content will be text If someone could point me in the right
direction to learn about this it would be greatly appreciated, Thanks, Ross
K.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default create macros that uses if-then-else statments

If Then statements are pretty straight foreward.
If Worksheets(1).Cells(1, 1).Value = “Hello World!” Then
MsgBox “Hello World!”
End If

But for what you’re asking about, use a Select Case statement instead.

Select Case Worksheets(1).Cells(1, 1).Value
Case1 “Hello World!”
MsgBox “Hello World!”
Case2 “Goodnight sweet prince.”
MsgBox “Hamlet”
Case3 etc…etc…etc…

End Select

VBA Help should have enough info to take it from here, but let us know
if it doesn't.

- Pikus


---
Message posted from http://www.ExcelForum.com/

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default create macros that uses if-then-else statments

Ross
I would use a Select Case construct with that many variables. HTH
Otto
"Ross K" wrote in message
...
I am new to using Macros and am looking for info on creating macros which

will allow me to use if-then-else statements based on set variables and then
print out the results of the conditional statement. For example: if
content of cell A1=var1, print statement1, elseif content cell A1= var2
print statement2, elseif content cell A1= var3 print statement3 and so on up
to var12. All content will be text If someone could point me in the right
direction to learn about this it would be greatly appreciated, Thanks, Ross
K.


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
If then Statments Tina Excel Worksheet Functions 5 January 20th 09 09:43 PM
If statments Lweiss Excel Worksheet Functions 2 March 20th 08 08:01 AM
If Statments Jason Excel Discussion (Misc queries) 2 January 3rd 08 05:33 PM
AND OR IF Statments Rogie Excel Worksheet Functions 3 February 12th 07 04:01 AM
Macros, How do I know what they do if I didn't create them. Abelg Excel Discussion (Misc queries) 1 September 17th 05 05:57 PM


All times are GMT +1. The time now is 07:57 PM.

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

About Us

"It's about Microsoft Excel"