Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Relative referencing

I don't think I'd use activecell and relative addressing. Since those formulas
depend on the cell you're in, it can get really confusing.

But you could plop formulas into a summary worksheet if you want:

Option Explicit
Sub testme()

Dim wks As Worksheet
Dim sumWks As Worksheet
Dim oRow As Long
Dim LastRow As Long

Set sumWks = Worksheets("summary")
oRow = 1 'some starting row

For Each wks In ActiveWorkbook.Worksheets
With wks
If .Name = sumWks.Name Then
'do nothing
Else
oRow = oRow + 1
sumWks.Cells(oRow, "A").Formula _
= "=" & .Range("a1").Address(external:=True)
sumWks.Cells(oRow, "B").Formula _
= "=" & .Range("b1").Address(external:=True)
'find lastrow of each worksheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
sumWks.Cells(oRow, "C").Formula _
= "=" & .Cells(LastRow, "A").Address(external:=True)
End If
End With
Next wks
End Sub

This creates a formula for A1, B1 and based on the last used cell in column A,
C###.




Alex wrote:

I found this on here a couple of days ago...

With ActiveCell
Set SumRange = Range(.Offset(-1), .Offset(-1).End(xlUp))
.Formula = "=sum( " & SumRange.Address(RowAbsolute:=False,
ColumnAbsolute:=False) & ")"
.Font.name = "Arial"
End With

This worked perfectly after I changed the offset ranges.

Now I have a question regarding referencing cells for data, as follows.

I have a maco that will generate reports as needed. Now I'm trying to wrap
it up to where it generates a summary worksheet. The thing is trying to get
all the data from the various worksheets that were generated on to the
summary worksheet. The generated worksheets are all unique in the number of
rows of data but have the same number of columns. I originally had a custom
macro just for myself and it took care of it all and worked great but now I'm
trying to port it out to other people where I work.

ActiveCell.Offset(1, -4).Range("A1").Select
ActiveCell.FormulaR1C1 = "=MZ6756!RC[1]"
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = "=MZ6756!RC[1]"
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = "=MZ6756!R[66]C[3]"

As you can see it gives the absolute value even though when I was recording
it as being relative. The question I have is, if I used the code up top,
modified to include the needed ranges, would it work? Would I need to add an
array or just reset the variable for each cell request? Other suggestions?

THANKS!!

--
Jack of all trades... master of none..


--

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
Referencing Relative Sheets jwatters Excel Worksheet Functions 4 January 4th 09 03:39 AM
Relative worksheet referencing Niju David Excel Discussion (Misc queries) 1 June 22nd 08 11:08 AM
Relative column referencing within formulas Alistair Excel Discussion (Misc queries) 4 February 23rd 06 05:38 PM
macro relative referencing harriet Excel Discussion (Misc queries) 5 February 15th 05 01:40 PM
Relative Indirect Formula Referencing? Damian Excel Worksheet Functions 1 January 7th 05 04:16 AM


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