Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default major errors with macro code - VB question constantly doing "ELSE" part of if statement

Hello

I have this part of my macro - No matter whether I click on yes to the
question or no it does not work........it is constanly running the
else macro whether or not you click "Yes" or "No"....

I've only just realised and it has caused me major problems.


If resp = MsgBox("Do you want to run macro1?", vbYesNo +
vbQuestion) = vbYes Then
Application.Run "'Workbook1 - Test.xls'!Macro1"
Else
Application.Run "'Workbook1 - Test.xls'!Macro2"
End If
Application.ScreenUpdating = True
If resp = MsgBox("Do you want to run macro3?", vbYesNo +
vbQuestion) = vbYes Then
Application.ScreenUpdating = False
Application.Run "'Workbook1 - Test.xls'!Macro3"
Else
Application.Run "'Workbook1 - Test.xls'!Macro4"
End If


In the above example it is always macros2 and 4 that are being
run.....

Please please please someone help,

I've spent so many hours working on this entire process for it to fail
on me......

thanks in advance for any help you may be able to provide,

Andrea

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default major errors with macro code - VB question constantly doing "ELSE"

If MsgBox("Do you want to run macro1?", _
vbYesNo + vbQuestion) = vbYes Then
Application.Run "'Workbook1 - Test.xls'!Macro1"
Else
Application.Run "'Workbook1 - Test.xls'!Macro2"
End If

Application.ScreenUpdating = True
If MsgBox("Do you want to run macro3?", _
vbYesNo + vbQuestion) = vbYes Then
Application.ScreenUpdating = False
Application.Run "'Workbook1 - Test.xls'!Macro3"
Else
Application.Run "'Workbook1 - Test.xls'!Macro4"
End If

--
Regards,
Tom Ogilvy

" wrote:

Hello

I have this part of my macro - No matter whether I click on yes to the
question or no it does not work........it is constanly running the
else macro whether or not you click "Yes" or "No"....

I've only just realised and it has caused me major problems.


If resp = MsgBox("Do you want to run macro1?", vbYesNo +
vbQuestion) = vbYes Then
Application.Run "'Workbook1 - Test.xls'!Macro1"
Else
Application.Run "'Workbook1 - Test.xls'!Macro2"
End If
Application.ScreenUpdating = True
If resp = MsgBox("Do you want to run macro3?", vbYesNo +
vbQuestion) = vbYes Then
Application.ScreenUpdating = False
Application.Run "'Workbook1 - Test.xls'!Macro3"
Else
Application.Run "'Workbook1 - Test.xls'!Macro4"
End If


In the above example it is always macros2 and 4 that are being
run.....

Please please please someone help,

I've spent so many hours working on this entire process for it to fail
on me......

thanks in advance for any help you may be able to provide,

Andrea


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default major errors with macro code - VB question constantly doing "ELSE" part of if statement

You're comparing the variable 'resp' to a comparision between the result
of the MsgBox and vbYes. The latter comparison returns True/False, and
the former then is always False.

Try either:

If MsgBox("Do you want to run macro1?", _
vbYesNo + vbQuestion) = vbYes Then
Application.Run "Macro1"
Else
Application.Run "'Macro2"
End If

Or

Dim resp As Long
resp = MsgBox("Do you want to run macro1?", _
vbYesNo + vbQuestion)
If resp = vbYes Then
Application.Run "Macro1"
Else
Application.Run "'Macro2"
End If





In article . com,
" wrote:

Hello

I have this part of my macro - No matter whether I click on yes to the
question or no it does not work........it is constanly running the
else macro whether or not you click "Yes" or "No"....

I've only just realised and it has caused me major problems.


If resp = MsgBox("Do you want to run macro1?", vbYesNo +
vbQuestion) = vbYes Then
Application.Run "'Workbook1 - Test.xls'!Macro1"
Else
Application.Run "'Workbook1 - Test.xls'!Macro2"
End If
Application.ScreenUpdating = True
If resp = MsgBox("Do you want to run macro3?", vbYesNo +
vbQuestion) = vbYes Then
Application.ScreenUpdating = False
Application.Run "'Workbook1 - Test.xls'!Macro3"
Else
Application.Run "'Workbook1 - Test.xls'!Macro4"
End If


In the above example it is always macros2 and 4 that are being
run.....

Please please please someone help,

I've spent so many hours working on this entire process for it to fail
on me......

thanks in advance for any help you may be able to provide,

Andrea

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
specify a certain cell format as part of an "if" statement Zeev Maoz Excel Discussion (Misc queries) 2 October 19th 09 10:22 PM
"If" statement returning blank gives downstream formula errors. Johnboy Excel Discussion (Misc queries) 2 February 26th 07 05:26 PM
"IF" Combo Formula, two part question pgarcia Excel Discussion (Misc queries) 6 February 21st 07 04:31 AM
Call a sub statement in "Personal Macro Workbook" from "ThisWorkbo QC Coug Excel Programming 1 August 26th 05 07:09 PM
"Save As" VBA code errors [email protected] Excel Programming 5 August 4th 05 05:54 PM


All times are GMT +1. The time now is 10:22 AM.

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"