Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Junior Member
 
Posts: 1
Default Worksheet name as a variable in VBA

Hello,

I am trying to use a cell value (C2 in the worksheet "Test") to dictate the worksheet I want to reference from in my if formula. In other words, all the '21-May' in my formula should be replaced by the cell value (C2) that refers to another worksheet. I replaced '21-May' with strName but it did not work. Will appreciate any help. Thank you.

Dim strName As String
strName = ActiveWorkbook.Sheets("Test").Range("C2").Value
Range("B36").Select
ActiveCell.FormulaR1C1 = _
"=IF(AND(R[-4]C[34]=0,R[-4]C[36]=0),0,(SUMIFS('21-May'!C21,'21-May'!C8,""CSA"",'21-May'!C9,""Late"")+SUMIFS('21-May'!C21,'21-May'!C8,""CSA"",'21-May'!C9,""Exception""))/(R[-4]C[34]+R[-4]C[36]))"
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 427
Default Worksheet name as a variable in VBA

When you replaced '21-May' with strName, did you include the apostrophes? In a formula the '21-May' is a reference to a tab, and the value in cell c2 likely does not include apostrophes. Excel rejects the formula written by VBA if the apostrophes are not present.
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
Link variable data from one worksheet to another worksheet? T MAT New Users to Excel 3 November 27th 07 06:46 AM
Variable worksheet name (tab) linked to cell in same worksheet azbob Excel Worksheet Functions 6 January 9th 07 06:27 PM
Looking up a variable in one worksheet and copying information from another column to another worksheet?? Brad Torken Excel Discussion (Misc queries) 2 December 10th 06 06:02 AM
Use a variable for a worksheet name? Frank Kabel Excel Programming 0 September 7th 04 10:57 PM
Assigning worksheet to worksheet variable PO Excel Programming 3 February 10th 04 02:22 PM


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