Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 361
Default How do I change the reference in a formula based on a logic test?

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,

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default How do I change the reference in a formula based on a logic test?

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" wrote in message
...
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,



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 361
Default How do I change the reference in a formula based on a logic te

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" wrote in message
...
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,




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default How do I change the reference in a formula based on a logic te

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 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" wrote in message
...
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,





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 361
Default How do I change the reference in a formula based on a logic te

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 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" wrote in message
...
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
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
How do I change the color of a cell in a logic formula color blind Excel Discussion (Misc queries) 1 June 22nd 07 05:44 AM
reference, test and change cell font. feedscrn Excel Programming 3 May 23rd 06 12:40 AM
logic test toolman New Users to Excel 1 October 8th 05 05:19 AM
change text color based on logical test T3nMan Excel Worksheet Functions 1 January 19th 05 04:30 PM
Logic test Ajit Excel Programming 1 October 13th 04 09:11 PM


All times are GMT +1. The time now is 01:03 AM.

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"