PC Review


Reply
Thread Tools Rate Thread

call duplicated

 
 
stan
Guest
Posts: n/a
 
      16th Aug 2009
New to VBA

I'm using the following code which is based on a range:

Sub update_finance()
'

If Range("b4").Value = "expenses1" Then Workbooks.Open
"C:\expenses1.xlsm"
Windows("dollars.xlsm").Activate
Sheets("Estimate").Select
Application.Run "'dollars.xlsm'!SAVE_expenses1"

If Range("b4").Value = "expenses2" Then Workbooks.Open "C:\expenses2.xlsm"
Windows("dollars.xlsm").Activate
Sheets("Estimate").Select
Application.Run "'dollars.xlsm'!SAVE_expenses2"
End Sub
--
"expenses1" runs OK but when I use "expenses2" in the cell it flips back to
the first one. I will have six range variables when I'm done but I didn't
see much sense in moving on until the first two are resolved.

Not sure how to remedy: if-then-else?


stan
 
Reply With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      16th Aug 2009
Probably because you are using the same sheet name in both workbooks, but
are not qualifying it when you refer to it with both workbooks open. You
should, either close the first workbook if you are finished with it before
opening the second one. Or you can use syntax like:

Workbooks("Expenses1").Sheets("Estimate").Select
Workbooks("Expensex2.")Sheets("Estimate").Select

That way, VBA knows which workbook you want to select Sheets("Extimate") in.


"stan" <(E-Mail Removed)> wrote in message
news:BC7BF90E-E98F-464A-9AB2-(E-Mail Removed)...
> New to VBA
>
> I'm using the following code which is based on a range:
>
> Sub update_finance()
> '
>
> If Range("b4").Value = "expenses1" Then Workbooks.Open
> "C:\expenses1.xlsm"
> Windows("dollars.xlsm").Activate
> Sheets("Estimate").Select
> Application.Run "'dollars.xlsm'!SAVE_expenses1"
>
> If Range("b4").Value = "expenses2" Then Workbooks.Open
> "C:\expenses2.xlsm"
> Windows("dollars.xlsm").Activate
> Sheets("Estimate").Select
> Application.Run "'dollars.xlsm'!SAVE_expenses2"
> End Sub
> --
> "expenses1" runs OK but when I use "expenses2" in the cell it flips back
> to
> the first one. I will have six range variables when I'm done but I didn't
> see much sense in moving on until the first two are resolved.
>
> Not sure how to remedy: if-then-else?
>
>
> stan



 
Reply With Quote
 
FSt1
Guest
Posts: n/a
 
      16th Aug 2009
hi
i think your structure is wrong. as is it is more top down than dicision
making.
try this ...
Sub update_finance2()

If Range("b4").Value = "expenses1" Then
Workbooks.Open "C:\expenses1.xlsm"
Windows("dollars.xlsm").Activate
Sheets("Estimate").Select
Application.Run "'dollars.xlsm'!SAVE_expenses1"
Else
If Range("b4").Value = "expenses2" Then
Workbooks.Open "C:\expenses2.xlsm"
Windows("dollars.xlsm").Activate
Sheets("Estimate").Select
Application.Run "'dollars.xlsm'!SAVE_expenses2"
End If
End If
End Sub

i don't have your data or macros so i only tested the decisions. they work
with the above structure.
regards
FSt1

"stan" wrote:

> New to VBA
>
> I'm using the following code which is based on a range:
>
> Sub update_finance()
> '
>
> If Range("b4").Value = "expenses1" Then Workbooks.Open
> "C:\expenses1.xlsm"
> Windows("dollars.xlsm").Activate
> Sheets("Estimate").Select
> Application.Run "'dollars.xlsm'!SAVE_expenses1"
>
> If Range("b4").Value = "expenses2" Then Workbooks.Open "C:\expenses2.xlsm"
> Windows("dollars.xlsm").Activate
> Sheets("Estimate").Select
> Application.Run "'dollars.xlsm'!SAVE_expenses2"
> End Sub
> --
> "expenses1" runs OK but when I use "expenses2" in the cell it flips back to
> the first one. I will have six range variables when I'm done but I didn't
> see much sense in moving on until the first two are resolved.
>
> Not sure how to remedy: if-then-else?
>
>
> stan

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Call a javascript when i call an aspx page with a form html not running on server Fabio Mastria Microsoft ASP .NET 4 28th Jan 2008 09:05 AM
Warning 1684 CA2214 : Microsoft.Usage : 'RandomShade..ctor(Int32, Int32, Int32, Int32, Int32)' contains a call chain that results in a call to a virtual method defined by the class. Review the following call stack for unintended consequences: steve bull Microsoft C# .NET 4 7th Jul 2005 05:54 PM
Are we new users supposed to call this number? I have auto dial on my XP in the dialer but am I required to call? Windows XP New Users 12 26th May 2005 03:47 PM
Please help - How to call functions that exists in the main application. The call should be initiated from one of the components. Anand Ganesh Microsoft C# .NET 5 16th Oct 2004 01:53 AM
disable call waiting on a local call puts in area code JMB Windows XP General 0 17th Feb 2004 10:32 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:59 PM.