Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Change sheet reference in formula?

XL2000

I have two workbooks, FOODCOST.XLS and INVENTORY TRACKING.XLS that are
individually updated monthly via macros

In INVENTORY TRACKING.XLS:
Cell B42 currently contains the formula
=SUMPRODUCT(('C:\DATA\EXCEL\[FOODCOST.XLS]Nov'!$M$5:$M$34)*('C:\DATA\EXCEL
\[FOODCOST.XLS]Nov'!$K$5:$K$34="Sysco"))
Cell G42 currently contains the formula
='C:\DATA\EXCEL\[FOODCOST.XLS]Nov'!$E$36

FOODCOST.XLS is updated monthly to add a sheet with the abbreviated name
for the next month. Is there some code I can add to an existing routine in
INVENTORY TRACKING.XLS that would automatically adjust these formulas to
refer to the latest month's sheet in FOODCOST.XLS?

Or could I change something in the formulas themselves that will tell them
to look at the range(s) in the latest sheet in FOODCOST.XLS?

--
David
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Change sheet reference in formula?

I think I'd do this:

Create a new sheet in Foodcost.xls and name it "myblankworksheet" (any valid
unique string of characters).

Then you could just edit|replace "myblankworksheet" with the name of the latest
month--but you'll have to know that.



David Turner wrote:

XL2000

I have two workbooks, FOODCOST.XLS and INVENTORY TRACKING.XLS that are
individually updated monthly via macros

In INVENTORY TRACKING.XLS:
Cell B42 currently contains the formula
=SUMPRODUCT(('C:\DATA\EXCEL\[FOODCOST.XLS]Nov'!$M$5:$M$34)*('C:\DATA\EXCEL
\[FOODCOST.XLS]Nov'!$K$5:$K$34="Sysco"))
Cell G42 currently contains the formula
='C:\DATA\EXCEL\[FOODCOST.XLS]Nov'!$E$36

FOODCOST.XLS is updated monthly to add a sheet with the abbreviated name
for the next month. Is there some code I can add to an existing routine in
INVENTORY TRACKING.XLS that would automatically adjust these formulas to
refer to the latest month's sheet in FOODCOST.XLS?

Or could I change something in the formulas themselves that will tell them
to look at the range(s) in the latest sheet in FOODCOST.XLS?

--
David


--

Dave Peterson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Change sheet reference in formula?

Dave Peterson wrote

I think I'd do this:

Create a new sheet in Foodcost.xls and name it "myblankworksheet" (any
valid unique string of characters).

Then you could just edit|replace "myblankworksheet" with the name of
the latest month--but you'll have to know that.


I don't follow, and forgive me if I'm missing the point.

Foodcost.xls already has a Sub NewMonth() routine that adds a sheet named
for the following month. Ex: when run from a TextBox button on Nov adds a
sheet named Dec. Section of that macro that does it:

srcName = ActiveSheet.Name
tgtName = Format(CDate(srcName & "-2002") + 32, "mmm")
Sheets(srcName).Copy After:=Sheets(srcName)
Sheets(srcName).TextBoxes.Delete
ActiveSheet.Name = tgtName

That said--after running that routine, I can switch to Food Inventory.xls
and edit|replace Nov with Dec to update the formulas there. Not the
solution I was looking for, but beats trying to edit the formulas from the
formula bar and risk missing one.

--
David
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Change sheet reference in formula?

How about having the NewMonth sub open the other worksheet and do the change
there, too. Have your macro change the old month ([FOODCOST.XLS]Nov) to the new
month.

(I mistakenly thought that there was a new worksheet (with formulas) being
created every month, too.)


David Turner wrote:

Dave Peterson wrote

I think I'd do this:

Create a new sheet in Foodcost.xls and name it "myblankworksheet" (any
valid unique string of characters).

Then you could just edit|replace "myblankworksheet" with the name of
the latest month--but you'll have to know that.


I don't follow, and forgive me if I'm missing the point.

Foodcost.xls already has a Sub NewMonth() routine that adds a sheet named
for the following month. Ex: when run from a TextBox button on Nov adds a
sheet named Dec. Section of that macro that does it:

srcName = ActiveSheet.Name
tgtName = Format(CDate(srcName & "-2002") + 32, "mmm")
Sheets(srcName).Copy After:=Sheets(srcName)
Sheets(srcName).TextBoxes.Delete
ActiveSheet.Name = tgtName

That said--after running that routine, I can switch to Food Inventory.xls
and edit|replace Nov with Dec to update the formulas there. Not the
solution I was looking for, but beats trying to edit the formulas from the
formula bar and risk missing one.

--
David


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Change sheet reference in formula?

Dave Peterson wrote

How about having the NewMonth sub open the other worksheet and do the
change there, too. Have your macro change the old month
([FOODCOST.XLS]Nov) to the new month.


I'm failing to visualize. Are you saying NewMonth() in Foodcost.xls could
update Inventory.xls formulas? If so, why can't that be done via Inventory
sub? Keep in mind Inventory.xls is not tabbed by month, and its current sub
only clears and transfers some named ranges to update it.

--
David


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Change sheet reference in formula?

Yep. I'm saying that the macro in FoodCost.xls could update the formulas in
inventory.xls.

dim InvWks as workbook
dim oldMonth as string
dim nextMonth as string
set invwks = workbooks.open("c:\yourpath\inventory.xls").worksh eets(1)

oldmonth = "[FOODCOST.XLS]Nov!"
nextmonth = "[FOODCOST.XLS]" & format(date,"mmm") & "!"

with invwks
.Cells.Replace What:=oldmonth, Replacement:=nextmonth, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
.parent.save
.parent.close savechanges:=false
end with

But I'm not sure how you know the name of the old month. Can it be retreived
from the system day (minus a week or two???) or could you save it somewhere else
so you could retreive it when you need it (a hidden worksheet???).

And yeah, if you know the months then you could put that macro in either spot.
But I'm still not sure how you know the old one and how you determine the new
one.

But if all else fails, you could just ask with a couple of inputboxes.


David Turner wrote:

Dave Peterson wrote

How about having the NewMonth sub open the other worksheet and do the
change there, too. Have your macro change the old month
([FOODCOST.XLS]Nov) to the new month.


I'm failing to visualize. Are you saying NewMonth() in Foodcost.xls could
update Inventory.xls formulas? If so, why can't that be done via Inventory
sub? Keep in mind Inventory.xls is not tabbed by month, and its current sub
only clears and transfers some named ranges to update it.

--
David


--

Dave Peterson

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Change sheet reference in formula?

Dave Peterson wrote

But if all else fails, you could just ask with a couple of inputboxes.


Since I want total control over when this book gets updated, and I don't
want to rely on the other book being opened, that's what I settled on:

'===stolen from a Google Groups post:
Dim wString As String
Dim rString As String
wString = InputBox("Enter 'What String'", "What String")
rString = InputBox("Enter 'Replacement String'", "Replacement String")
Cells.Replace What:=wString, _
Replacement:=rString, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
MatchCase:=False

I did have to change the wording in a couple of descriptive cells to avoid
them being changed.

Thanks for hanging in there with me.

--
David
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Change sheet reference in formula?

Dave Peterson wrote

But I'm not sure how you know the name of the old month.


That was the reason for my original post, asking if maybe I could reference
a sheet index of Foodcost.xls or something like that.

--
David
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Change sheet reference in formula?

Dave Peterson wrote

But I'm not sure how you know the name of the old month.


Hmm...

This worked as long as Foodcost.xls was open:

wString = Workbooks("foodcost.xls").Sheets(5).Name
rString = Workbooks("foodcost.xls").Sheets(6).Name
Cells.Replace What:=wString, _
Replacement:=rString, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
MatchCase:=False

--
David
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Change sheet reference in formula?

Dave Peterson wrote

And yeah, if you know the months then you could put that macro in
either spot. But I'm still not sure how you know the old one and how
you determine the new one.


"Cake and eat it, too" final code:

Sub Renew()
Dim OldMonth As String
Dim NewMonth As String
Dim wkbk As Workbook
Set wkbk = ActiveWorkbook
Application.ScreenUpdating = False
Workbooks.Open "Foodcost.xls"
wkbk.Activate
Range("Initial_Qty").Value = Range("On_Hand").Value
Range("Added_Used").ClearContents
OldMonth = Workbooks("foodcost.xls").Sheets(5).Name
NewMonth = Workbooks("foodcost.xls").Sheets(6).Name
Cells.Replace What:=OldMonth, _
Replacement:=NewMonth, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
MatchCase:=False
Workbooks("Foodcost.xls").Close
Application.ScreenUpdating = True
End Sub

--
David
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
Graph data series formulas: How to global-change all sheet reference to formula [email protected] Excel Discussion (Misc queries) 1 January 20th 09 05:32 AM
How to change a reference when the sheet change the folder? WonderOlga Excel Worksheet Functions 2 January 3rd 08 09:19 PM
Is it possible to change a Sheet reference in a formula? Stuart Peters Excel Discussion (Misc queries) 1 June 16th 06 10:54 PM
Change the work sheet name in a formula by using cell reference Neel Excel Worksheet Functions 1 June 12th 06 09:24 AM
Change workbook sheet reference using cell A1 to change a vairable Reed Excel Worksheet Functions 4 January 20th 05 07:15 PM


All times are GMT +1. The time now is 10:55 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"