Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Average of one range based on date in one column

Lets say my sheet looks like this after the data is
entered and the advanced filter hides row 6. Which has
the number value of 2. And a Text3 value that is not equal
to xx. Although the date value is 1/3/04

A B C D E F
1 Text3
2 xx
3
4 Name Date Text1 Text2 Text3 number
5 " " 1/1/04 " " " " xx 12
7 " " 1/5/04 " " " " xx 15
---------------------------------------------------
8 Jan Avg 14
9 Feb Avg

What I want is to create in VB the algorithm that will
insert the average formula into cell F8 inserting only the
range values that are in January lets say and Text3.
Or b/c the data is filtered just based on the visible date
values take that dates corresponding number and place that
in the Average range holder. I want cell F8 to look like
this = Avg(F5,F7) but I want to have it automatically done
by searching the visible date values in column B and then
taking the corresponding number in column F and placing it
into the range the the Average funciton will specify.
I have thought about doing an advanced filter with the
copy to range in another sheet but to me there is to much
information and calculations that are done by automation,
defined names etc.... that would be wiped out once that
copy to was done.
If anyone understands what I am looking to do please
respond. Thank you.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Average of one range based on date in one column

Dim rng as Range, rng1 as Range, cell as Range

set rng = Range(Range("F5"),ActiveCell.offset(-1,0))
set rng1 = nothing
for each cell in rng
if cell.Entirerow.Hidden = False _
and Format(cell.offset(0,-3),"mmm") = _
left(Activecell.offset(0,-5),3) then
if rng1 is nothing then
set rng1 = cell
else
set rng1 = union(rng1,cell)
end if
End if
Next
ActiveCell.Formula = "=Average(" & rng1.Address & ")"

A lot would depend on how and when you plan to run the macro. This assumes
F8 is the activeCell.


--
Regards,
Tom Ogilvy


"Matt" wrote in message
...
Lets say my sheet looks like this after the data is
entered and the advanced filter hides row 6. Which has
the number value of 2. And a Text3 value that is not equal
to xx. Although the date value is 1/3/04

A B C D E F
1 Text3
2 xx
3
4 Name Date Text1 Text2 Text3 number
5 " " 1/1/04 " " " " xx 12
7 " " 1/5/04 " " " " xx 15
---------------------------------------------------
8 Jan Avg 14
9 Feb Avg

What I want is to create in VB the algorithm that will
insert the average formula into cell F8 inserting only the
range values that are in January lets say and Text3.
Or b/c the data is filtered just based on the visible date
values take that dates corresponding number and place that
in the Average range holder. I want cell F8 to look like
this = Avg(F5,F7) but I want to have it automatically done
by searching the visible date values in column B and then
taking the corresponding number in column F and placing it
into the range the the Average funciton will specify.
I have thought about doing an advanced filter with the
copy to range in another sheet but to me there is to much
information and calculations that are done by automation,
defined names etc.... that would be wiped out once that
copy to was done.
If anyone understands what I am looking to do please
respond. Thank you.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Average of one range based on date in one column

Thank You Tom.
-----Original Message-----
Dim rng as Range, rng1 as Range, cell as Range

set rng = Range(Range("F5"),ActiveCell.offset(-1,0))
set rng1 = nothing
for each cell in rng
if cell.Entirerow.Hidden = False _
and Format(cell.offset(0,-3),"mmm") = _
left(Activecell.offset(0,-5),3) then
if rng1 is nothing then
set rng1 = cell
else
set rng1 = union(rng1,cell)
end if
End if
Next
ActiveCell.Formula = "=Average(" & rng1.Address & ")"

A lot would depend on how and when you plan to run the

macro. This assumes
F8 is the activeCell.


--
Regards,
Tom Ogilvy


"Matt" wrote in

message
...
Lets say my sheet looks like this after the data is
entered and the advanced filter hides row 6. Which has
the number value of 2. And a Text3 value that is not

equal
to xx. Although the date value is 1/3/04

A B C D E F
1 Text3
2 xx
3
4 Name Date Text1 Text2 Text3 number
5 " " 1/1/04 " " " " xx 12
7 " " 1/5/04 " " " " xx 15
---------------------------------------------------
8 Jan Avg 14
9 Feb Avg

What I want is to create in VB the algorithm that will
insert the average formula into cell F8 inserting only

the
range values that are in January lets say and Text3.
Or b/c the data is filtered just based on the visible

date
values take that dates corresponding number and place

that
in the Average range holder. I want cell F8 to look

like
this = Avg(F5,F7) but I want to have it automatically

done
by searching the visible date values in column B and

then
taking the corresponding number in column F and placing

it
into the range the the Average funciton will specify.
I have thought about doing an advanced filter with the
copy to range in another sheet but to me there is to

much
information and calculations that are done by

automation,
defined names etc.... that would be wiped out once that
copy to was done.
If anyone understands what I am looking to do please
respond. Thank you.



.

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
Count Unique Values in 1 Column based on Date Range in another Column Brian Excel Worksheet Functions 14 May 17th 09 02:58 PM
calculate average in a column based on criteria in another column sharon t Excel Discussion (Misc queries) 2 May 12th 06 06:07 PM
Count cells based on date range in another column [email protected] New Users to Excel 1 May 5th 05 08:11 PM
Can you average data in 1 column based on a range of values in another? kman24 Excel Worksheet Functions 2 November 17th 04 02:09 PM
vba: Taking average of values in one column based on a corresponding value in another column eggsell Excel Programming 7 August 5th 03 01:12 PM


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