PC Review


Reply
Thread Tools Rate Thread

Calculating Only Visiable Data

 
 
paddy_nyr
Guest
Posts: n/a
 
      20th Jul 2007
I have a multi column spreadsheet and let's say that in column P I have
numeric values. I then filter the data and I only want to calulate the
average on what visable on the screen.

I created this sub routine to average my column datasets, but again when the
user filters I'd like to calculate on the visable dataset.

I'm using Excel 2003 running Windows XP

Thanks


Sub AverageData()

Dim a_avg As Currency
Dim a_tcc As Currency
Dim a_aip As Currency

Dim a_test As Currency

X = Cells(Rows.Count, "c").End(xlUp).Row

Cells(X + 2, "p") = Application.Average(Range("p2" & X))
Cells(X + 2, "v") = Application.Average(Range("v2:v" & X))
Cells(X + 2, "w") = Application.Average(Range("w2:w" & X))


a_avg = Application.Average(Range("p2" & X))
a_tcc = Application.Average(Range("v2:v" & X))
a_aip = Application.Average(Range("w2:w" & X))

a_avg = Application.Average(Range("p2"))


MsgBox " Your new Avg Salary is now : " & a_avg

End Sub


 
Reply With Quote
 
 
 
 
=?Utf-8?B?QW5vbnk=?=
Guest
Posts: n/a
 
      20th Jul 2007
You don't need a macro to calculate the average of filtered cells. Just use
this worksheet function:
=SUBTOTAL(1, your entire range here)
 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      20th Jul 2007
Sub avervisible()
mysum = 0
On Error Resume Next
For Each c In Range("a1:a" & Cells(Rows.Count, "a").End(xlUp).Row)
If c.EntireRow.Hidden <> True Then
mysum = mysum + c.Value
mc = mc + 1
End If
Next
MsgBox mysum
MsgBox mc
MsgBox mysum / mc
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"paddy_nyr" <(E-Mail Removed)> wrote in message
news:46a0e432$0$97267$(E-Mail Removed)...
>I have a multi column spreadsheet and let's say that in column P I have
>numeric values. I then filter the data and I only want to calulate the
>average on what visable on the screen.
>
> I created this sub routine to average my column datasets, but again when
> the user filters I'd like to calculate on the visable dataset.
>
> I'm using Excel 2003 running Windows XP
>
> Thanks
>
>
> Sub AverageData()
>
> Dim a_avg As Currency
> Dim a_tcc As Currency
> Dim a_aip As Currency
>
> Dim a_test As Currency
>
> X = Cells(Rows.Count, "c").End(xlUp).Row
>
> Cells(X + 2, "p") = Application.Average(Range("p2" & X))
> Cells(X + 2, "v") = Application.Average(Range("v2:v" & X))
> Cells(X + 2, "w") = Application.Average(Range("w2:w" & X))
>
>
> a_avg = Application.Average(Range("p2" & X))
> a_tcc = Application.Average(Range("v2:v" & X))
> a_aip = Application.Average(Range("w2:w" & X))
>
> a_avg = Application.Average(Range("p2"))
>
>
> MsgBox " Your new Avg Salary is now : " & a_avg
>
> End Sub
>
>


 
Reply With Quote
 
paddy_nyr
Guest
Posts: n/a
 
      20th Jul 2007
"Don Guillett" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Sub avervisible()
> mysum = 0
> On Error Resume Next
> For Each c In Range("a1:a" & Cells(Rows.Count, "a").End(xlUp).Row)
> If c.EntireRow.Hidden <> True Then
> mysum = mysum + c.Value
> mc = mc + 1
> End If
> Next
> MsgBox mysum
> MsgBox mc
> MsgBox mysum / mc
> End Sub
>
> --
> Don Guillett
> Microsoft MVP Excel
> SalesAid Software
> (E-Mail Removed)
> "paddy_nyr" <(E-Mail Removed)> wrote in message

Thanks Don that did it.


 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      20th Jul 2007
Glad to help. Subtotal is better but you asked for VBA

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"paddy_nyr" <(E-Mail Removed)> wrote in message
news:46a0f28c$0$97239$(E-Mail Removed)...
> "Don Guillett" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Sub avervisible()
>> mysum = 0
>> On Error Resume Next
>> For Each c In Range("a1:a" & Cells(Rows.Count, "a").End(xlUp).Row)
>> If c.EntireRow.Hidden <> True Then
>> mysum = mysum + c.Value
>> mc = mc + 1
>> End If
>> Next
>> MsgBox mysum
>> MsgBox mc
>> MsgBox mysum / mc
>> End Sub
>>
>> --
>> Don Guillett
>> Microsoft MVP Excel
>> SalesAid Software
>> (E-Mail Removed)
>> "paddy_nyr" <(E-Mail Removed)> wrote in message

> Thanks Don that did it.
>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Import export not visiable in the file menu. DL Microsoft Outlook Installation 0 15th Apr 2009 08:16 PM
Import export not visiable in the file menu. strangeoccurrances Microsoft Outlook Installation 0 15th Apr 2009 08:07 PM
Sheet name is not visiable. Heera Microsoft Excel Programming 5 25th Feb 2009 10:10 PM
Sum Visiable Values Only =?Utf-8?B?TWFyayBKYWNrc29u?= Microsoft Access Reports 1 4th Nov 2006 11:15 PM
Keeping column titles visiable Sonars_UK Microsoft Excel Discussion 2 6th Nov 2004 06:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:52 AM.