Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default VBA code to find specific data by name. Get average. Put in cell.

(See Sheet Below)I need code that would find the name in C column and get the
Test Result associated with that name in the D column. Do this each time it
sees that name, average the results, and place that result in another
specific cell.

For example!!, find each PPerson in range C:2 to C:8 and get corresponding
Result in the D column.
C:4--* 98.7
C:6--* 99.5
C:7--* 99.7

B C D E F G H
1 Date Analyst Results Analyst Avg. Coun
2 EJackson 98.4 2
3 3/20/08 EJackson 99.2 PPerson 99.3 3
4 3/20/08 PPerson 98.7 MSilverton 99.2 1
5 3/20/08 MSilveton 99.2
6 3/20/08 PPerson 99.5
7 3/20/08 PPerson 99.7
8 3/20/08 EJackson 97.6




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default VBA code to find specific data by name. Get average. Put in cell.

You don't need a macro to do this calculation.

Try this:

In G2, put this

=average(if(C3:C8=F2,D3:D8))

Commit with CTRL SHIFT ENTER
--
HTH,
Barb Reinhardt



"Jplink49" wrote:

(See Sheet Below)I need code that would find the name in C column and get the
Test Result associated with that name in the D column. Do this each time it
sees that name, average the results, and place that result in another
specific cell.

For example!!, find each PPerson in range C:2 to C:8 and get corresponding
Result in the D column.
C:4--* 98.7
C:6--* 99.5
C:7--* 99.7

B C D E F G H
1 Date Analyst Results Analyst Avg. Coun
2 EJackson 98.4 2
3 3/20/08 EJackson 99.2 PPerson 99.3 3
4 3/20/08 PPerson 98.7 MSilverton 99.2 1
5 3/20/08 MSilveton 99.2
6 3/20/08 PPerson 99.5
7 3/20/08 PPerson 99.7
8 3/20/08 EJackson 97.6




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 141
Default VBA code to find specific data by name. Get average. Put in cell.

On Mar 20, 11:46 am, Jplink49
wrote:
(See Sheet Below)I need code that would find the name in C column and get the
Test Result associated with that name in the D column. Do this each time it
sees that name, average the results, and place that result in another
specific cell.

For example!!, find each "PPerson" in range C:2 to C:8 and get corresponding
Result in the D column.
C:4-- 98.7
C:6-- 99.5
C:7-- 99.7

B C D E F G H
1 Date Analyst Results Analyst Avg. Coun
2 EJackson 98.4 2
3 3/20/08 EJackson 99.2 PPerson 99.3 3
4 3/20/08 PPerson 98.7 MSilverton 99.2 1
5 3/20/08 MSilveton 99.2
6 3/20/08 PPerson 99.5
7 3/20/08 PPerson 99.7
8 3/20/08 EJackson 97.6


That's something like this:

private sub makesum()

dim sngResult as Single
dim strTarget as string

strTarget = inputbox("Enter name","Sum Results")

do until cells(icounter,2)="" 'until no more dates
if cells(icounter,3)=strTarget Then
sngResult = sngResult + cells(icounter,4)
end if
icounter = icounter + 1
loop

call msgbox(strtarget & " has a sum of " &
sngresult,vbokonly,"Result")


end sub



cheers
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 141
Default VBA code to find specific data by name. Get average. Put in cell.

On Mar 20, 12:11 pm, cht13er wrote:
On Mar 20, 11:46 am, Jplink49
wrote:





(See Sheet Below)I need code that would find the name in C column and get the
Test Result associated with that name in the D column. Do this each time it
sees that name, average the results, and place that result in another
specific cell.


For example!!, find each "PPerson" in range C:2 to C:8 and get corresponding
Result in the D column.
C:4-- 98.7
C:6-- 99.5
C:7-- 99.7


B C D E F G H
1 Date Analyst Results Analyst Avg. Coun
2 EJackson 98.4 2
3 3/20/08 EJackson 99.2 PPerson 99.3 3
4 3/20/08 PPerson 98.7 MSilverton 99.2 1
5 3/20/08 MSilveton 99.2
6 3/20/08 PPerson 99.5
7 3/20/08 PPerson 99.7
8 3/20/08 EJackson 97.6


That's something like this:

private sub makesum()

dim sngResult as Single
dim strTarget as string

strTarget = inputbox("Enter name","Sum Results")

do until cells(icounter,2)="" 'until no more dates
if cells(icounter,3)=strTarget Then
sngResult = sngResult + cells(icounter,4)
end if
icounter = icounter + 1
loop

call msgbox(strtarget & " has a sum of " &
sngresult,vbokonly,"Result")

end sub

cheers- Hide quoted text -

- Show quoted text -




EDIT:

To get the average, simply count the number of times you add to the
sum and divide when you're done .... to put in a cell just do exactly
that :)

Sorry for not reading the question fully :0

Chris
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default VBA code to find specific data by name. Get average. Put in ce

Barb, this works. Thanks a lot.

"Barb Reinhardt" wrote:

You don't need a macro to do this calculation.

Try this:

In G2, put this

=average(if(C3:C8=F2,D3:D8))

Commit with CTRL SHIFT ENTER
--
HTH,
Barb Reinhardt



"Jplink49" wrote:

(See Sheet Below)I need code that would find the name in C column and get the
Test Result associated with that name in the D column. Do this each time it
sees that name, average the results, and place that result in another
specific cell.

For example!!, find each PPerson in range C:2 to C:8 and get corresponding
Result in the D column.
C:4--* 98.7
C:6--* 99.5
C:7--* 99.7

B C D E F G H
1 Date Analyst Results Analyst Avg. Coun
2 EJackson 98.4 2
3 3/20/08 EJackson 99.2 PPerson 99.3 3
4 3/20/08 PPerson 98.7 MSilverton 99.2 1
5 3/20/08 MSilveton 99.2
6 3/20/08 PPerson 99.5
7 3/20/08 PPerson 99.7
8 3/20/08 EJackson 97.6






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default VBA code to find specific data by name. Get average. Put in ce

Cht13er,

Thanks for responding to my questions. I'm going to try this code on my test
app. Thanks again, I let you know how it works.

"cht13er" wrote:

On Mar 20, 12:11 pm, cht13er wrote:
On Mar 20, 11:46 am, Jplink49
wrote:





(See Sheet Below)I need code that would find the name in C column and get the
Test Result associated with that name in the D column. Do this each time it
sees that name, average the results, and place that result in another
specific cell.


For example!!, find each "PPerson" in range C:2 to C:8 and get corresponding
Result in the D column.
C:4--* 98.7
C:6--* 99.5
C:7--* 99.7


B C D E F G H
1 Date Analyst Results Analyst Avg. Coun
2 EJackson 98.4 2
3 3/20/08 EJackson 99.2 PPerson 99.3 3
4 3/20/08 PPerson 98.7 MSilverton 99.2 1
5 3/20/08 MSilveton 99.2
6 3/20/08 PPerson 99.5
7 3/20/08 PPerson 99.7
8 3/20/08 EJackson 97.6


That's something like this:

private sub makesum()

dim sngResult as Single
dim strTarget as string

strTarget = inputbox("Enter name","Sum Results")

do until cells(icounter,2)="" 'until no more dates
if cells(icounter,3)=strTarget Then
sngResult = sngResult + cells(icounter,4)
end if
icounter = icounter + 1
loop

call msgbox(strtarget & " has a sum of " &
sngresult,vbokonly,"Result")

end sub

cheers- Hide quoted text -

- Show quoted text -




EDIT:

To get the average, simply count the number of times you add to the
sum and divide when you're done .... to put in a cell just do exactly
that :)

Sorry for not reading the question fully :0

Chris

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default VBA code to find specific data by name. Get average. Put in ce

Hey Barb

Your formula worked; however what can I add to the formula to handle cases
were the (If) is FALSE. I get that #DIV/0! message. How can I modify it so it
will come back an empty string or even a dash (-). Without getting that
#VALUE!



"Barb Reinhardt" wrote:

You don't need a macro to do this calculation.

Try this:

In G2, put this

=average(if(C3:C8=F2,D3:D8))

Commit with CTRL SHIFT ENTER
--
HTH,
Barb Reinhardt



"Jplink49" wrote:

(See Sheet Below)I need code that would find the name in C column and get the
Test Result associated with that name in the D column. Do this each time it
sees that name, average the results, and place that result in another
specific cell.

For example!!, find each PPerson in range C:2 to C:8 and get corresponding
Result in the D column.
C:4--* 98.7
C:6--* 99.5
C:7--* 99.7

B C D E F G H
1 Date Analyst Results Analyst Avg. Coun
2 EJackson 98.4 2
3 3/20/08 EJackson 99.2 PPerson 99.3 3
4 3/20/08 PPerson 98.7 MSilverton 99.2 1
5 3/20/08 MSilveton 99.2
6 3/20/08 PPerson 99.5
7 3/20/08 PPerson 99.7
8 3/20/08 EJackson 97.6




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 411
Default VBA code to find specific data by name. Get average. Put in ce

Try this:

=IF(ISERROR(AVERAGE(IF(C3:C8=F2,D3:D8))),"",AVERAG E(IF(C3:C8=F2,D3:D8)))
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default VBA code to find specific data by name. Get average. Put in ce

Dan, that formula worked. Thanks Buddy.

"dan dungan" wrote:

Try this:

=IF(ISERROR(AVERAGE(IF(C3:C8=F2,D3:D8))),"",AVERAG E(IF(C3:C8=F2,D3:D8)))

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 411
Default VBA code to find specific data by name. Get average. Put in ce

Glad to help
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 do i find specific data in a cell and its colocated cell data sfself Excel Worksheet Functions 4 March 27th 09 08:23 AM
code to go down a column and find the last cell with data before an empty cell Steve G Excel Programming 1 July 23rd 07 08:22 AM
Macro to find specific data in a cell, then delete that row on down MultiMatt Excel Programming 1 May 15th 07 07:06 PM
UDF code to find specific text in cell comments, then average cell values bruch04 Excel Programming 3 December 5th 05 10:01 PM
how do I find an average number of specific words in a column cashgrfx New Users to Excel 7 January 6th 05 04:44 PM


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