Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Formula Referencing Worksheet Name by Variable

Concatenation should work:

Set OldSht = ActiveSheet
Sheets.Add
NewShtName = ActiveSheet.Name
OldSht.Activate
Cells(1, 1).Formula = "='" & NewShtName & "'!A2"

"dafio" wrote:

I am setting up a macro that will add a new worksheet to a workbook. The macro will then need to enter a formula in a cell on an existing worksheet that references a cell on the new worksheet. I am assuming I can use a variable for the new worksheet name and concatenate it within the formula but it doesn't work.

e.g. - If the new worksheet is named "Smith", I would need to use VBA to enter the following formula on an existing worksheet:

=Smith!A2

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
Replace worksheet without affecting the referencing formula Jay Excel Discussion (Misc queries) 1 May 7th 09 03:11 AM
Variable Worksheet Name in Formula pdberger Excel Worksheet Functions 4 March 16th 08 12:28 AM
Same formula referencing same cells returns incorrect results, randomly, when pasted into new worksheet [email protected] Excel Worksheet Functions 1 March 9th 06 07:55 PM
referencing worksheet as a variable crew3407 Excel Programming 3 April 28th 04 08:48 PM
Referencing variable Lee Excel Programming 1 December 4th 03 04:07 PM


All times are GMT +1. The time now is 04:21 PM.

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"