PC Review


Reply
Thread Tools Rate Thread

How do I change the reference in a formula based on a logic test?

 
 
Carl
Guest
Posts: n/a
 
      2nd Jul 2008
I need the formula to change the name of the source file based on a logic
test. For examle, how would I change the following so that it references a
different file name based on the day of the month?
='C:\[MTG Source File 1.xls]Sheet1'!$A$1
I know how to get the day of the month, just haven't been able to get the
name of the file to change in the formula without a reference error. Thanks
so much in advance,

 
Reply With Quote
 
 
 
 
Bernie Deitrick
Guest
Posts: n/a
 
      2nd Jul 2008
With the activecell as the cell with the formula

='C:\[MTG Source File 1.xls]Sheet1'!$A$1

Sub ChangeFileNameTest()
Dim myFormula As String
Dim myFName As String
myFormula = ActiveCell.Formula
myFName = "MTG Source File " & Day(Date) & ".xls"
myFormula = Left(myFormula, InStr(1, myFormula, "[")) & myFName &
Mid(myFormula, InStr(1, myFormula, "]"))
MsgBox "Here's the new formula: " & myFormula
ActiveCell.Formula = myFormula
End Sub

Of course, the logic I used for the myFName wasn't based on anything other
than a wild guess....

HTH,
Bernie
MS Excel MVP

"Carl" <(E-Mail Removed)> wrote in message
news94B028D-6329-4F3B-915C-(E-Mail Removed)...
>I need the formula to change the name of the source file based on a logic
> test. For examle, how would I change the following so that it references a
> different file name based on the day of the month?
> ='C:\[MTG Source File 1.xls]Sheet1'!$A$1
> I know how to get the day of the month, just haven't been able to get the
> name of the file to change in the formula without a reference error.
> Thanks
> so much in advance,
>



 
Reply With Quote
 
Carl
Guest
Posts: n/a
 
      2nd Jul 2008
Thanks, Bernie,
I think you are very close but I got a syntax error on the following steps
(turned red) and could not figure out how to correct it:

myFormula = Left(myFormula, InStr(1, myFormula, "[")) & myFName &
Mid(myFormula, InStr(1, myFormula, "]"))

Thanks again, Carl

"Bernie Deitrick" wrote:

> With the activecell as the cell with the formula
>
> ='C:\[MTG Source File 1.xls]Sheet1'!$A$1
>
> Sub ChangeFileNameTest()
> Dim myFormula As String
> Dim myFName As String
> myFormula = ActiveCell.Formula
> myFName = "MTG Source File " & Day(Date) & ".xls"
> myFormula = Left(myFormula, InStr(1, myFormula, "[")) & myFName &
> Mid(myFormula, InStr(1, myFormula, "]"))
> MsgBox "Here's the new formula: " & myFormula
> ActiveCell.Formula = myFormula
> End Sub
>
> Of course, the logic I used for the myFName wasn't based on anything other
> than a wild guess....
>
> HTH,
> Bernie
> MS Excel MVP
>
> "Carl" <(E-Mail Removed)> wrote in message
> news94B028D-6329-4F3B-915C-(E-Mail Removed)...
> >I need the formula to change the name of the source file based on a logic
> > test. For examle, how would I change the following so that it references a
> > different file name based on the day of the month?
> > ='C:\[MTG Source File 1.xls]Sheet1'!$A$1
> > I know how to get the day of the month, just haven't been able to get the
> > name of the file to change in the formula without a reference error.
> > Thanks
> > so much in advance,
> >

>
>
>

 
Reply With Quote
 
Gord Dibben
Guest
Posts: n/a
 
      2nd Jul 2008
Carl

Those two lines are actually all one line.

Enter a line-continuation character and try again..

myFormula = Left(myFormula, InStr(1, myFormula, "[")) & myFName & _
Mid(myFormula, InStr(1, myFormula, "]"))



Gord Dibben MS Excel MVP

On Wed, 2 Jul 2008 13:20:01 -0700, Carl <(E-Mail Removed)> wrote:

>Thanks, Bernie,
>I think you are very close but I got a syntax error on the following steps
>(turned red) and could not figure out how to correct it:
>
>myFormula = Left(myFormula, InStr(1, myFormula, "[")) & myFName &
>Mid(myFormula, InStr(1, myFormula, "]"))
>
>Thanks again, Carl
>
>"Bernie Deitrick" wrote:
>
>> With the activecell as the cell with the formula
>>
>> ='C:\[MTG Source File 1.xls]Sheet1'!$A$1
>>
>> Sub ChangeFileNameTest()
>> Dim myFormula As String
>> Dim myFName As String
>> myFormula = ActiveCell.Formula
>> myFName = "MTG Source File " & Day(Date) & ".xls"
>> myFormula = Left(myFormula, InStr(1, myFormula, "[")) & myFName &
>> Mid(myFormula, InStr(1, myFormula, "]"))
>> MsgBox "Here's the new formula: " & myFormula
>> ActiveCell.Formula = myFormula
>> End Sub
>>
>> Of course, the logic I used for the myFName wasn't based on anything other
>> than a wild guess....
>>
>> HTH,
>> Bernie
>> MS Excel MVP
>>
>> "Carl" <(E-Mail Removed)> wrote in message
>> news94B028D-6329-4F3B-915C-(E-Mail Removed)...
>> >I need the formula to change the name of the source file based on a logic
>> > test. For examle, how would I change the following so that it references a
>> > different file name based on the day of the month?
>> > ='C:\[MTG Source File 1.xls]Sheet1'!$A$1
>> > I know how to get the day of the month, just haven't been able to get the
>> > name of the file to change in the formula without a reference error.
>> > Thanks
>> > so much in advance,
>> >

>>
>>
>>


 
Reply With Quote
 
Carl
Guest
Posts: n/a
 
      2nd Jul 2008
That took care of the problem. Thanks to both of you.

"Gord Dibben" wrote:

> Carl
>
> Those two lines are actually all one line.
>
> Enter a line-continuation character and try again..
>
> myFormula = Left(myFormula, InStr(1, myFormula, "[")) & myFName & _
> Mid(myFormula, InStr(1, myFormula, "]"))
>
>
>
> Gord Dibben MS Excel MVP
>
> On Wed, 2 Jul 2008 13:20:01 -0700, Carl <(E-Mail Removed)> wrote:
>
> >Thanks, Bernie,
> >I think you are very close but I got a syntax error on the following steps
> >(turned red) and could not figure out how to correct it:
> >
> >myFormula = Left(myFormula, InStr(1, myFormula, "[")) & myFName &
> >Mid(myFormula, InStr(1, myFormula, "]"))
> >
> >Thanks again, Carl
> >
> >"Bernie Deitrick" wrote:
> >
> >> With the activecell as the cell with the formula
> >>
> >> ='C:\[MTG Source File 1.xls]Sheet1'!$A$1
> >>
> >> Sub ChangeFileNameTest()
> >> Dim myFormula As String
> >> Dim myFName As String
> >> myFormula = ActiveCell.Formula
> >> myFName = "MTG Source File " & Day(Date) & ".xls"
> >> myFormula = Left(myFormula, InStr(1, myFormula, "[")) & myFName &
> >> Mid(myFormula, InStr(1, myFormula, "]"))
> >> MsgBox "Here's the new formula: " & myFormula
> >> ActiveCell.Formula = myFormula
> >> End Sub
> >>
> >> Of course, the logic I used for the myFName wasn't based on anything other
> >> than a wild guess....
> >>
> >> HTH,
> >> Bernie
> >> MS Excel MVP
> >>
> >> "Carl" <(E-Mail Removed)> wrote in message
> >> news94B028D-6329-4F3B-915C-(E-Mail Removed)...
> >> >I need the formula to change the name of the source file based on a logic
> >> > test. For examle, how would I change the following so that it references a
> >> > different file name based on the day of the month?
> >> > ='C:\[MTG Source File 1.xls]Sheet1'!$A$1
> >> > I know how to get the day of the month, just haven't been able to get the
> >> > name of the file to change in the formula without a reference error.
> >> > Thanks
> >> > so much in advance,
> >> >
> >>
> >>
> >>

>
>

 
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
How can I reference a worksheet in a formula based on a cell value JZinGA Microsoft Excel Worksheet Functions 2 3rd May 2010 10:57 PM
How do I change the color of a cell in a logic formula =?Utf-8?B?Y29sb3IgYmxpbmQ=?= Microsoft Excel Misc 1 22nd Jun 2007 05:44 AM
Formula to lookup named reference based on value Santa-D Microsoft Excel Discussion 2 20th Jun 2007 02:32 PM
reference, test and change cell font. feedscrn Microsoft Excel Programming 3 23rd May 2006 12:40 AM
change text color based on logical test =?Utf-8?B?VDNuTWFu?= Microsoft Excel Worksheet Functions 1 19th Jan 2005 04:30 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:33 PM.