Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Copy worksheet to new doc w/formulas not referencing previous doc | Excel Discussion (Misc queries) | |||
Formula - Referencing Between Worksheets | Excel Discussion (Misc queries) | |||
Array formula referencing other worksheets | Excel Worksheet Functions | |||
Formula Referencing data on multiple worksheets | Excel Worksheet Functions | |||
Referencing previous column in COUNTIF | Excel Discussion (Misc queries) |