LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Adding a coulmn total using a range name and sheet name

Burl,
Am using CountA instead of Count.
Also, using EntireColumn creates a circular reference.
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware/

'--------------------------
Sub Named_Range()
Dim s1 As String
Dim s2 As String
Dim sName As String
s1 = ActiveSheet.Name
s2 = "'" & s1 & "'"

sName = Cells(2, ActiveCell.Column).Value
ThisWorkbook.Names.Add Name:=sName & "_" & s1, _
RefersTo:="=OFFSET(" & s2 & "!" & Cells(2, ActiveCell.Column).Address & _
",1,0,COUNTA(" & s2 & "!" & Range(Cells(2, ActiveCell.Column), _
Cells(Rows.Count, ActiveCell.Column)).Address & ")-1,1)"

'This adds the formula...
Cells(1, ActiveCell.Column).Formula = "=Sum(" & sName & "_" & s1 & ")"

Debug.Print sName & "_" & s1, ThisWorkbook.Names( _
sName & "_" & s1).RefersTo
End Sub
'-------------------


"burl_rfc_h" wrote in message
In the code below I created a dynamic range, the range name is based on
the contents in cell 2 of a column (in this case text) and the sheet
name. How can I then place a formula into the 1st cell of the column
that totals up the contents of the dynamic range, using the dynmaic
range name.

Sub Named_Range()
Dim s1 As String
Dim s2 As String
Dim sName As String
s1 = ActiveSheet.Name
s2 = "'" & s1 & "'"
sName = Cells(2, ActiveCell.Column).Value
ThisWorkbook.Names.Add Name:=sName & "_" & s1, _
RefersTo:="=OFFSET(" & s2 & "!" & Cells(2, _
ActiveCell.Column).Address & _
",1,0,COUNT(" & s2 & "!" & _
ActiveCell.EntireColumn.Address & ")-1,1)"
Debug.Print sName & "_" & s1, ThisWorkbook.Names( _
sName & "_" & s1).RefersTo
End Sub
Thanks
Burl
 
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
Revisit an older post, looking for SQL help on adding range data frommany sheets to a single sheet Rick[_10_] Excel Worksheet Functions 4 May 31st 09 09:02 PM
HOW DO I COPY A TOTAL FIGURE FROM 1 SHEET TO NEXT ADDING RUNNING T SANDRA Excel Worksheet Functions 0 October 8th 07 01:27 PM
Sum total formula for adding 2 columnson time sheet John Sullivan Excel Worksheet Functions 1 October 21st 05 03:30 PM
Adding Data Using Multiple Worksheets to Total into a Grand Total Lillie Excel Worksheet Functions 1 April 19th 05 08:34 PM
Adding sub-total Elsie Excel Programming 2 February 28th 04 06:34 AM


All times are GMT +1. The time now is 07:32 AM.

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"