Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Referencing previous worksheets in formula


I am working on a macro to copy the last worksheet in a workbook at the
end of the existing worksheets and input formulas in the new worksheet
that reference the previous worksheet.

For example, consider the following code:

Dim ws As Worksheet

Set ws = Worksheets(Worksheets.Count)
ws.Copy After:=ws
Set ws = Worksheets(Worksheets.Count)
ws.Range("A1").Formula = “=’Sheet1’!A1 + 1”

How can I replace the ‘Sheet1’ name with the name of the previous
worksheet?

My attempt that resulted in a run-time error was:

ws.Range("A1").Formula =
“=Worksheets(Worksheets.Count-1).Range(“A1”) + 1”


Any suggestions are appreciated.

Thanks,

Carey


--
cnaquin
------------------------------------------------------------------------
cnaquin's Profile: http://www.excelforum.com/member.php...o&userid=26242
View this thread: http://www.excelforum.com/showthread...hreadid=395345

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Referencing previous worksheets in formula

Untested but give this a try...

ws.Range("A1").Formula =
"=" & Worksheets(Worksheets.Count-1).Name & "!A1 + 1"

--
HTH...

Jim Thomlinson


"cnaquin" wrote:


I am working on a macro to copy the last worksheet in a workbook at the
end of the existing worksheets and input formulas in the new worksheet
that reference the previous worksheet.

For example, consider the following code:

Dim ws As Worksheet

Set ws = Worksheets(Worksheets.Count)
ws.Copy After:=ws
Set ws = Worksheets(Worksheets.Count)
ws.Range("A1").Formula = €œ=Sheet1!A1 + 1€

How can I replace the €˜Sheet1 name with the name of the previous
worksheet?

My attempt that resulted in a run-time error was:

ws.Range("A1").Formula =
€œ=Worksheets(Worksheets.Count-1).Range(€œA1€) + 1€


Any suggestions are appreciated.

Thanks,

Carey


--
cnaquin
------------------------------------------------------------------------
cnaquin's Profile: http://www.excelforum.com/member.php...o&userid=26242
View this thread: http://www.excelforum.com/showthread...hreadid=395345


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Referencing previous worksheets in formula


That's it!!!!!!!!!

Thanks a bunch Jim

--
cnaqui
-----------------------------------------------------------------------
cnaquin's Profile: http://www.excelforum.com/member.php...fo&userid=2624
View this thread: http://www.excelforum.com/showthread.php?threadid=39534

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Referencing previous worksheets in formula


With a bit of testing, it looks like this works if there is not a space
in the worksheet name. What should the code be if it is unknown that
the worksheet name has a space or not?

Thanks,

Carey Naquin


--
cnaquin
------------------------------------------------------------------------
cnaquin's Profile: http://www.excelforum.com/member.php...o&userid=26242
View this thread: http://www.excelforum.com/showthread...hreadid=395345

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
Copy worksheet to new doc w/formulas not referencing previous doc Feolet20 Excel Discussion (Misc queries) 4 June 30th 09 10:56 PM
Formula - Referencing Between Worksheets 1S2RSK Excel Discussion (Misc queries) 1 January 2nd 08 07:18 AM
Array formula referencing other worksheets broderp Excel Worksheet Functions 1 December 8th 06 09:27 PM
Formula Referencing data on multiple worksheets ChrisPrather Excel Worksheet Functions 6 August 22nd 06 05:14 AM
Referencing previous column in COUNTIF [email protected] Excel Discussion (Misc queries) 6 March 1st 05 10:27 AM


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