Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
G G is offline
external usenet poster
 
Posts: 52
Default loops and count

Hi The Any assistance will be highly appreciated. I am trying to loop
through a 2D array where it goes through each row. and counts the Xs
corresponding to the value. For example, Ideally 10 should have a count of 2
x's, 14 a cnt of 1 x , 12 0 etc..
10 X
12
14 X
13
10 X
10
Thanks in advance
G
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default loops and count

You may try the macros below:

You can change the value in subroutine €śgo_count€ť so that the macro looks
for different values.

Sub go_count()
MsgBox xcount(20)
End Sub

Function xcount(ByVal x)
xcount = 0
Dim cell As Object
For Each cell In Selection.Columns(1).Cells
If cell.Value = x Then
If UCase(cell.Offset(0, 1).Value) = "X" Then
xcount = xcount + 1
End If
End If
Next
End Function

Regards,
Edwin Tam

http://www.vonixx.com


"G" wrote:

Hi The Any assistance will be highly appreciated. I am trying to loop
through a 2D array where it goes through each row. and counts the Xs
corresponding to the value. For example, Ideally 10 should have a count of 2
x's, 14 a cnt of 1 x , 12 0 etc..
10 X
12
14 X
13
10 X
10
Thanks in advance
G

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default loops and count

You could use SUMPRODUCT like this

=SUMPRODUCT(--(A1:A6=D1),--(B1:B6="X"))

in cell D1 , insert the number you want to do a count on. Incorporating this
into your spreadsheet may be a better option than VBA.

Rich

"G" wrote:

Hi The Any assistance will be highly appreciated. I am trying to loop
through a 2D array where it goes through each row. and counts the Xs
corresponding to the value. For example, Ideally 10 should have a count of 2
x's, 14 a cnt of 1 x , 12 0 etc..
10 X
12
14 X
13
10 X
10
Thanks in advance
G

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default loops and count

You could also use SUMPRODUCT in VBA

evaluate("SUMPRODUCT(--(A1:A6=D1),--(B1:B6=""X""))")

but do you mean a worksheet range, or are you referring to a VBA array?

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Rich" <rich@hotmail wrote in message
...
You could use SUMPRODUCT like this

=SUMPRODUCT(--(A1:A6=D1),--(B1:B6="X"))

in cell D1 , insert the number you want to do a count on. Incorporating

this
into your spreadsheet may be a better option than VBA.

Rich

"G" wrote:

Hi The Any assistance will be highly appreciated. I am trying to loop
through a 2D array where it goes through each row. and counts the Xs
corresponding to the value. For example, Ideally 10 should have a count

of 2
x's, 14 a cnt of 1 x , 12 0 etc..
10 X
12
14 X
13
10 X
10
Thanks in advance
G



  #5   Report Post  
Posted to microsoft.public.excel.programming
G G is offline
external usenet poster
 
Posts: 52
Default loops and count

Hi thanks for all your help, I mean a VBA array, because it will be looking
for the value X in different cells, going down each row.



"Bob Phillips" wrote:

You could also use SUMPRODUCT in VBA

evaluate("SUMPRODUCT(--(A1:A6=D1),--(B1:B6=""X""))")

but do you mean a worksheet range, or are you referring to a VBA array?

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Rich" <rich@hotmail wrote in message
...
You could use SUMPRODUCT like this

=SUMPRODUCT(--(A1:A6=D1),--(B1:B6="X"))

in cell D1 , insert the number you want to do a count on. Incorporating

this
into your spreadsheet may be a better option than VBA.

Rich

"G" wrote:

Hi The Any assistance will be highly appreciated. I am trying to loop
through a 2D array where it goes through each row. and counts the Xs
corresponding to the value. For example, Ideally 10 should have a count

of 2
x's, 14 a cnt of 1 x , 12 0 etc..
10 X
12
14 X
13
10 X
10
Thanks in advance
G






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default loops and count

when you say a 2D array, is this a vba array in memory or are you talking
about a range of cells on a worksheet?

--
Regards,
Tom Ogilvy


"G" wrote in message
...
Hi The Any assistance will be highly appreciated. I am trying to loop
through a 2D array where it goes through each row. and counts the Xs
corresponding to the value. For example, Ideally 10 should have a count of

2
x's, 14 a cnt of 1 x , 12 0 etc..
10 X
12
14 X
13
10 X
10
Thanks in advance
G



  #7   Report Post  
Posted to microsoft.public.excel.programming
G G is offline
external usenet poster
 
Posts: 52
Default loops and count

Range of cells on a worksheet.

"Tom Ogilvy" wrote:

when you say a 2D array, is this a vba array in memory or are you talking
about a range of cells on a worksheet?

--
Regards,
Tom Ogilvy


"G" wrote in message
...
Hi The Any assistance will be highly appreciated. I am trying to loop
through a 2D array where it goes through each row. and counts the Xs
corresponding to the value. For example, Ideally 10 should have a count of

2
x's, 14 a cnt of 1 x , 12 0 etc..
10 X
12
14 X
13
10 X
10
Thanks in advance
G




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default loops and count

You really don't need code to do this

assume your data is in column A and B
in rows 1 to 1000

=Sumproduct(--($A$1:$A$1000=14),--($B$1:$B$1000="X"))

You can replace 1 with a cell reference. So say in E1 to E10 you put in
the numbers 10 to 20

in F1 you would put
=Sumproduct(--($A$1:$A$1000=E1),--($B$1:$B$1000="X"))

then drag fill down to F10.

--
Regards,
Tom Ogilvy


"G" wrote in message
...
Range of cells on a worksheet.

"Tom Ogilvy" wrote:

when you say a 2D array, is this a vba array in memory or are you

talking
about a range of cells on a worksheet?

--
Regards,
Tom Ogilvy


"G" wrote in message
...
Hi The Any assistance will be highly appreciated. I am trying to

loop
through a 2D array where it goes through each row. and counts the Xs
corresponding to the value. For example, Ideally 10 should have a

count of
2
x's, 14 a cnt of 1 x , 12 0 etc..
10 X
12
14 X
13
10 X
10
Thanks in advance
G






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
Loops [email protected] Excel Discussion (Misc queries) 2 October 14th 06 02:52 PM
do loops saravanan Excel Worksheet Functions 0 June 13th 06 10:53 AM
Do loops grandfilth Excel Discussion (Misc queries) 1 November 10th 05 12:00 AM
Using For - Next Loops in VB Biomed New Users to Excel 4 March 22nd 05 07:12 PM
help with loops Rick B[_6_] Excel Programming 8 January 28th 04 12:32 AM


All times are GMT +1. The time now is 12:00 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"