PC Review


Reply
Thread Tools Rate Thread

copying a template sheet and inputting a formula into another sheetthat references the new sheet

 
 
A & S
Guest
Posts: n/a
 
      29th Jul 2009
Hi here is the section of code that I am having problems with, I have
it commented to help anyone understand what I am doing. Everything
works except for the last line of code. The big picture of what I am
trying to do is to make a copy of an existing template worksheet that
I have setup, then I want the macro to input a formula into the my
Main worksheet that references cells in the newly created worksheet.


'This variable store the name of the new sheet that it gets from an
existing cell
newSht = ActiveCell.FormulaR1C1

‘Creating a copy of the template worksheet and renaming it to the
value stored in variable newSht
Sheets("Worksheet Template").Select
Sheets("Worksheet Template").Copy Before:=Sheets(3)
ActiveSheet.Name = newSht

‘Inputting a formula to the main worksheet that references the newly
created template copy
Sheets("Main Worksheet").Select
ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = "=('newsht'!R30C7*'newsht'!R51C7)"



Thanks
 
Reply With Quote
 
 
 
 
jasontferrell
Guest
Posts: n/a
 
      29th Jul 2009
Change the last line as follows:
ActiveCell.FormulaR1C1 = "=('" & newsht & "'!R30C7*'" & newsht & "'!
R51C7)"
The variable needs to be referenced outside of the quotation marks.
 
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
Copying rows values on one sheet to part of a formula in a column onanother sheet. Manosh Microsoft Excel Discussion 2 23rd Jun 2009 03:58 AM
Copying a formatted "template" sheet and naming new sheet via user form Neale Microsoft Excel Programming 1 31st May 2007 04:02 PM
Copying sheet containing GetPivotData, new sheet references old workbook! rivkarak Microsoft Excel Programming 0 18th Jan 2007 11:31 AM
when copying sheet, warning that formula or sheet Mark Microsoft Excel Discussion 5 31st May 2005 09:30 PM
Copying a sheet with namd references Michael Microsoft Excel Misc 1 12th May 2004 11:47 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:36 AM.