LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
 
Posts: n/a
Default Referencing cell in another sheet yields null?

This problem has a bit of history, but I will cut it down to the bare
bones. I have a workbook that starts with three sheets called Semester
1, Semester Template, and Totals. I have a macro on Totals that creates
a sheet for the next semester before Semester Template, in this case it
would be Semester 2. Then, the macro inserts a number of columns equal
to the number of Mondays in the semester. For instance for Fall 2005,
there are 27 weeks from August 1-January 31 (I need our semesters to
overlap for the project, so Fall ends in January.) so there are 27
columns between A and the last column headed as Total. This Total
column for the semester sheet has an INDIRECT formula for summing that
particular row from B:[Total column - 1]. These totals work great. The
last the thing macro does is create a column on Totals to reference the
semester Total column from the new semester sheet that was created. In
the appropriate cell, I need to reference the corresponding category's
Total on the semester sheet. I have attempted to do this a number of
ways, but all to no avail. The code I have should work in my limited
understanding but it doesn't. Any help would be immensely appreciated.

ActiveCell.Value = "=INDIRECT(ADDRESS(4," & NewSemLastCol & ",,," &
NewSem &")"

The address I am referencing with the above code contains this formula:

=SUM(INDIRECT("B4:"&ADDRESS(ROW(),COLUMN()-1)))

NewSemLastCol is an integer variable that is equal to the number of
Mondays in the semester plus two, which yields that last column number
on the semester sheet. NewSem is a variable containing the name of the
sheet for the newly added semester. NewSem works for sure because I
have used it in another reference on the Totals sheet.

Sheets("Totals").Activate
Range("A1").Select
ActiveCell.Offset(0, LastSheet - 1).EntireColumn.Insert
ActiveCell.Offset(0, LastSheet - 1).Value = "='" & NewSem & "'!A2"
ActiveCell.Offset(0, LastSheet - 1).Columns.AutoFit

NewSem!A2 is the term and year, i.e. Fall 2005, Spring 2006, etc. on
the semester sheet. The code above puts the term and year as the column
heading in the Totals sheet's column for that semester's totals. The
only difference between NewSem!A2 and the cell I am trying to reference
is that A2 has a string while the cell I want to reference has the
SUM(INDIRECT()) formula from above. When I enter the cell reference in
Excel as

='Semester 2'!AC4 (which is what the reference works out to with the
NewSemLastCol and NewSem variables)

the total value from that cell shows up nicely in my Totals sheet. I
just cannot for the life of me get it to work in VBA. Thanks in advance
for your help. If I need to post more info/data, I will be happy to do
so.

 
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
Text from one sheet cell to appear in another sheet cell mduck Excel Worksheet Functions 6 May 23rd 13 08:35 PM
referencing Excel sheet name in cell Graham Tritton Excel Worksheet Functions 1 October 14th 05 06:53 AM
Getting contents of a cell when cell reference is in the sheet A Nelson Excel Discussion (Misc queries) 3 October 5th 05 06:46 PM
Cell linked to a range of cell values in different sheet szeng Excel Discussion (Misc queries) 1 August 9th 05 02:41 AM
Automatic cell increment with data from sheet 1 to sheet 2 Big G Excel Worksheet Functions 2 December 20th 04 05:59 PM


All times are GMT +1. The time now is 05:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"