Alexandre Brisebois (www.pointnetsolutions.com)
Guest
Creating a Macros function but co9ntent of function only works in a sub plz help
Hey, I am creating a function that need to go read off of different
sheets andsum up a specific cell on all active sheets defined on the
first summary sheet.
the problem is that the code works great in a sub since i have to move
from sheet to sheet but when i get to a function it simply does not
work any more...
to find the cell i need to sum i have to locate specific content of a
cell in a cpecific column in this case the column is A & i must look
for the content of the cells then offset from it and sum the value on
all th esheets specified on the frist sheet where the names of the
sheets are available.
Any ideas?
Code --->>>
Public Function SumTotal(ByRef cellref As Object, offsetBy As Integer)
On Error Resume Next
Dim accumulator As Double
Dim start As String
start = ActiveSheet.Name
Dim InRange As Range
'get the active sheet names.
Set InRange = Intersect(ActiveSheet.UsedRange, Columns("AX:AX"))
Dim Rng As Range
Dim tempRng As Range
'Application.Volatile True
'sum all sheet values
For Each Rng In InRange.Cells
If Not (IsEmpty(Rng)) Then
Sheets(Rng.Value).Select
Range("A1").Select
Cells.Find(What:=cellref.Value, After:=ActiveCell,
LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows,
SearchDirection:=xlNext, _
MatchCase:=False).Activate
ActiveCell.Offset(rowOffset:=0,
columnOffset:=offsetBy).Activate
accumulator = accumulator + ActiveCell.Value
End If
Next Rng
Sheets(start).Select
SumTotal = accumulator
End Function
Bookmarks