Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
al al is offline
external usenet poster
 
Posts: 363
Default Referencing Diff Sheet in Formula in VBA

Right now I have a code line in my macro which says:
Range(CellLocation).Value = "=SUBTOTAL(9,'Main'!R1C5:R200C5)"

I want to replace 'Main' with a variable name (SheetName) that represents a
sheet name. I get errors if I if replace 'Main' with SheetName or
'SheetName'. Is it possible to do what I want?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Referencing Diff Sheet in Formula in VBA

maybe...

Range(CellLocation).FormulaR1C1 _
= "=SUBTOTAL(9,'" & yourVariableHere & "'!R1C5:R200C5)"

If you used a variable to represent the worksheet (not the worksheet name):

Range(CellLocation).FormulaR1C1 _
= "=SUBTOTAL(9,'" & yourWksVariable.Name & "'!R1C5:R200C5)"


I also changed .value to .formular1c1.

Al wrote:

Right now I have a code line in my macro which says:
Range(CellLocation).Value = "=SUBTOTAL(9,'Main'!R1C5:R200C5)"

I want to replace 'Main' with a variable name (SheetName) that represents a
sheet name. I get errors if I if replace 'Main' with SheetName or
'SheetName'. Is it possible to do what I want?


--

Dave Peterson
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
make formula look at diff sheet wx4usa Excel Discussion (Misc queries) 5 December 26th 09 07:07 PM
SUMIF formula required to search for 2 diff values in 2 diff colum Lidy693 Excel Worksheet Functions 7 February 21st 09 09:45 PM
Problem w/formula referencing another sheet PatrickP Excel Worksheet Functions 1 January 15th 08 04:42 AM
copy formula referencing sheet name to another sheet Tat Excel Worksheet Functions 1 June 26th 05 03:00 AM
Referencing Sheet Names In Formula Paul Gurdin Excel Programming 3 October 5th 03 10:36 AM


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