Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How do I reference Current Cell when cell isn't the Activecell

Greetings and Happy Holidays!

I am stuck on a cell referencing issue

I am looking to total 1 row in column T based on if a date
in column Q falls
within a 52 week range from a date in a cell. Then
looking to average some weekly
outstanding amounts from column T that fall within this 52
week range. Maybe someone knows of another way like an
indirect lookup method but I am using VBA.

HERE is my problem with my VBA CODE:

I want to create this into a function using the offset
method but I
don't know how to reference the "current" cell because its
not the "active cell". Since it's not the active cell, I
can't use "Activecell.Offset(-2,0).Value" in my function.
Here is the Pseudo code. Could someone help me with the
missing link?

Public Sub FiftyTwoWeekAvg()

Dim SettlementDate As Range
Dim sh As Worksheet
Dim SheetCount As Integer

' Set NewOutstanding to zero
NewOutstanding = 0

' Find out how many worksheets there are in this workbook
SheetCount = ThisWorkbook.Worksheets.count

' Need to replace following code with something like the
following
Set SettlementDate = Cells(CurrentCell).Offset(0,-2)

' Run through the sheets and grab the outstandings
For x = 1 To SheetCount
Set sh = Worksheets(x)
For i = 10 To 1000
If IsDate(Cells(i, 17)) Then
If (DateDiff("w", Cells(i, 17),
SettlementDate) <= 52) Then
NewOutstanding = NewOutstanding + Cells(i -
2, 20)
NumberofWeeks = NumberofWeeks + 1
End If
End If
Next i
Next x
' return the value for the FiftyTwoWeekAvg
FiftyTwoWeekAvg = NewOutstanding / NumberofWeeks
End Function

Can you help?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How do I reference Current Cell when cell isn't the Activecell

if you mean the currentcell is the cell containing the formula, then you can
use

Dim cell as Range
set cell = Application.Caller

--
Regards,
Tom Ogilvy

"VBA2VBZGuy" wrote in message
...
Greetings and Happy Holidays!

I am stuck on a cell referencing issue

I am looking to total 1 row in column T based on if a date
in column Q falls
within a 52 week range from a date in a cell. Then
looking to average some weekly
outstanding amounts from column T that fall within this 52
week range. Maybe someone knows of another way like an
indirect lookup method but I am using VBA.

HERE is my problem with my VBA CODE:

I want to create this into a function using the offset
method but I
don't know how to reference the "current" cell because its
not the "active cell". Since it's not the active cell, I
can't use "Activecell.Offset(-2,0).Value" in my function.
Here is the Pseudo code. Could someone help me with the
missing link?

Public Sub FiftyTwoWeekAvg()

Dim SettlementDate As Range
Dim sh As Worksheet
Dim SheetCount As Integer

' Set NewOutstanding to zero
NewOutstanding = 0

' Find out how many worksheets there are in this workbook
SheetCount = ThisWorkbook.Worksheets.count

' Need to replace following code with something like the
following
Set SettlementDate = Cells(CurrentCell).Offset(0,-2)

' Run through the sheets and grab the outstandings
For x = 1 To SheetCount
Set sh = Worksheets(x)
For i = 10 To 1000
If IsDate(Cells(i, 17)) Then
If (DateDiff("w", Cells(i, 17),
SettlementDate) <= 52) Then
NewOutstanding = NewOutstanding + Cells(i -
2, 20)
NumberofWeeks = NumberofWeeks + 1
End If
End If
Next i
Next x
' return the value for the FiftyTwoWeekAvg
FiftyTwoWeekAvg = NewOutstanding / NumberofWeeks
End Function

Can you help?




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How do I reference Current Cell when cell isn't the Activecell



Tom,

Using the following, gives me 'Object Required' Error '424'.



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
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
How to reference the current total, when it could be Cell H9 or H2 Gina[_2_] Excel Discussion (Misc queries) 3 August 7th 08 09:59 PM
Relative/Current Cell Reference in Hyperlinks cncf Excel Discussion (Misc queries) 0 June 1st 08 09:46 PM
Inserting current date when number entered in cell & Circular reference error? Pheasant Plucker® Excel Discussion (Misc queries) 4 April 10th 07 10:39 AM
Reference of current cell [email protected] Excel Discussion (Misc queries) 4 July 24th 06 08:19 PM
Cell reference to current cell minus 1 Jared Mortlock Excel Worksheet Functions 3 November 10th 05 01:58 AM


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