Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Count each group of values

I need a formula or vba code to count how many groups of "X" values and how
many "X" in each group.
Sample:

a1
ah1
X X X X X X X A A A A X X X X X X B B B B B B X X X X X X X X X X X X

Result i need with the code or formula
1 group 7 "x"
2 group 6 "x"
3 group 12"x"

Thanks for help
Paulo



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Count each group of values

JP

I'm assuming that the data is in the range A1 - AI1 inclusive (rather than in the range A1 - AH1 or all in one cell). If so, then this should help.

Tony

Sub bbb()
grpcnt = 0

Range("a1").Select
While Not IsEmpty(ActiveCell)
If ActiveCell = "X" Then
grpcnt = grpcnt + 1
thisgrp = 0
While ActiveCell = "X"
thisgrp = thisgrp + 1
ActiveCell.Offset(0, 1).Select
Wend
End If
If ActiveCell < "X" Then
Range("a1").Offset(grpcnt, 0).Value = grpcnt & " group " & thisgrp & " ""x"""
ActiveCell.Offset(0, 1).Select
End If
Wend

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default Count each group of values

JP,

This counts the group in a selection. If more than one row is selected, an
x in the new row starts a new group no matter what.

Sub test2()

Dim r, x_range As Range
Dim x_counter, group_counter, i As Long
Dim msg As String

msg = ""

For Each r In Selection
If UCase(r) = "X" Then
If x_range Is Nothing Then
Set x_range = r
Else
Set x_range = Union(x_range, r)
End If
End If
Next r

For i = 1 To x_range.Areas.Count
msg = msg & "Group " & i & ":" & x_range.Areas(i).Cells.Count & " x" &
vbCrLf
Next i

MsgBox msg

End Sub
"JP" wrote in message
...
I need a formula or vba code to count how many groups of "X" values and

how
many "X" in each group.
Sample:

a1
ah1
X X X X X X X A A A A X X X X X X B B B B B B X X X X X X X X X X X X

Result i need with the code or formula
1 group 7 "x"
2 group 6 "x"
3 group 12"x"

Thanks for help
Paulo





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default Count each group of values

woops, left in a couple of extra variables there, so for the sake of
neatness:

Dim r, x_range As Range
Dim i As Long
Dim msg As String

msg = ""

For Each r In Selection
If UCase(r) = "X" Then
If x_range Is Nothing Then
Set x_range = r
Else
Set x_range = Union(x_range, r)
End If
End If
Next r

For i = 1 To x_range.Areas.Count
msg = msg & "Group " & i & ":" & x_range.Areas(i).Cells.Count & " x" &
vbCrLf
Next i

MsgBox msg

End Sub

hth,

Doug

"JP" wrote in message
...
I need a formula or vba code to count how many groups of "X" values and

how
many "X" in each group.
Sample:

a1
ah1
X X X X X X X A A A A X X X X X X B B B B B B X X X X X X X X X X X X

Result i need with the code or formula
1 group 7 "x"
2 group 6 "x"
3 group 12"x"

Thanks for help
Paulo





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Count each group of values

Thank you very much for your help ACW.

Thank you very much "Doug Glancy", your solution is the best for my work.
Before this solution i need a lot of formulas to get the some results, now
is very simple with your code.

It's possible get the msg results in a range of cells? I need the values
number of counted "x" to calculate another things.
Sample: If a group of "x" = 7 then 7*another value

Thanks for your dedicated attention.I have excel experience but in vba i'm a
novice.
Excuse for my english.
Paulo Coelho





"Doug Glancy" wrote in message
...
woops, left in a couple of extra variables there, so for the sake of
neatness:

Dim r, x_range As Range
Dim i As Long
Dim msg As String

msg = ""

For Each r In Selection
If UCase(r) = "X" Then
If x_range Is Nothing Then
Set x_range = r
Else
Set x_range = Union(x_range, r)
End If
End If
Next r

For i = 1 To x_range.Areas.Count
msg = msg & "Group " & i & ":" & x_range.Areas(i).Cells.Count & " x" &
vbCrLf
Next i

MsgBox msg

End Sub

hth,

Doug

"JP" wrote in message
...
I need a formula or vba code to count how many groups of "X" values and

how
many "X" in each group.
Sample:

a1
ah1
X X X X X X X A A A A X X X X X X B B B B B B X X X X X X X X X X X X

Result i need with the code or formula
1 group 7 "x"
2 group 6 "x"
3 group 12"x"

Thanks for help
Paulo









  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default Count each group of values

JP,

Here's one that puts the results in rows in the Column A below any other
data. If you need something else, let me know. I changed a couple of other
things too:

Sub test()
Dim r, x_range, result_range As Range
Dim i As Long
Dim msg As String

msg = ""
For Each r In Selection
If UCase(r) = "X" Then
If IsEmpty(x_range) Then
Set x_range = r
Else
Set x_range = Union(x_range, r)
End If
End If
Next r

If Not IsEmpty(x_range) Then
Set result_range = ActiveSheet.Range("A" & ActiveSheet.Range("A" &
Rows.Count).End(xlUp).Row + 3)
With result_range
.Cells(0, 1) = "Group"
.Cells(0, 2) = "X count"
For i = 1 To x_range.Areas.Count
.Cells(i, 1) = i
.Cells(i, 2) = x_range.Areas(i).Cells.Count
Next i
End With
Else
MsgBox "No Xs in selected area"
End If

End Sub

hth,

Doug
"JP" wrote in message
...
Thank you very much for your help ACW.

Thank you very much "Doug Glancy", your solution is the best for my work.
Before this solution i need a lot of formulas to get the some results, now
is very simple with your code.

It's possible get the msg results in a range of cells? I need the values
number of counted "x" to calculate another things.
Sample: If a group of "x" = 7 then 7*another value

Thanks for your dedicated attention.I have excel experience but in vba i'm

a
novice.
Excuse for my english.
Paulo Coelho





"Doug Glancy" wrote in message
...
woops, left in a couple of extra variables there, so for the sake of
neatness:

Dim r, x_range As Range
Dim i As Long
Dim msg As String

msg = ""

For Each r In Selection
If UCase(r) = "X" Then
If x_range Is Nothing Then
Set x_range = r
Else
Set x_range = Union(x_range, r)
End If
End If
Next r

For i = 1 To x_range.Areas.Count
msg = msg & "Group " & i & ":" & x_range.Areas(i).Cells.Count & " x"

&
vbCrLf
Next i

MsgBox msg

End Sub

hth,

Doug

"JP" wrote in message
...
I need a formula or vba code to count how many groups of "X" values

and
how
many "X" in each group.
Sample:

a1
ah1
X X X X X X X A A A A X X X X X X B B B B B B X X X X X X X X X X X X

Result i need with the code or formula
1 group 7 "x"
2 group 6 "x"
3 group 12"x"

Thanks for help
Paulo









  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Count each group of values

Hello Doug

Thanks for your colaboration.
Another help please:

Itīs possible fix the results in a range of cells. I need the values always
in some cells to make calculations.
Sample:A1:A7 groups; B1:B7 x counts and C1:C7 where y put my needed
calculations to be used by entire Worksheet functions
The ranges are flexible, another ranges be Ok.
A B C
Group X count Hours
1 5 30
2 4 24
3 10 48
4 2 12
5 3 18
6 4 24


Im a Health worker and this Worksheet is intended to count the lacks of my
personal group of workers in the hospital.
1 "x" = 1/5 of the week of work(30 hours) = 6
2 "x" = 2/5 .... =12
3 "x" = 3/5 .... =18
4 "x" = 4/5 .... =24
5, 6 or 7 "x" = 5/5 .... =30

Thanks for your attention
Best Regards
Paulo Coelho




"Doug Glancy" wrote in message
...
JP,

Here's one that puts the results in rows in the Column A below any other
data. If you need something else, let me know. I changed a couple of

other
things too:

Sub test()
Dim r, x_range, result_range As Range
Dim i As Long
Dim msg As String

msg = ""
For Each r In Selection
If UCase(r) = "X" Then
If IsEmpty(x_range) Then
Set x_range = r
Else
Set x_range = Union(x_range, r)
End If
End If
Next r

If Not IsEmpty(x_range) Then
Set result_range = ActiveSheet.Range("A" & ActiveSheet.Range("A" &
Rows.Count).End(xlUp).Row + 3)
With result_range
.Cells(0, 1) = "Group"
.Cells(0, 2) = "X count"
For i = 1 To x_range.Areas.Count
.Cells(i, 1) = i
.Cells(i, 2) = x_range.Areas(i).Cells.Count
Next i
End With
Else
MsgBox "No Xs in selected area"
End If

End Sub

hth,

Doug
"JP" wrote in message
...
Thank you very much for your help ACW.

Thank you very much "Doug Glancy", your solution is the best for my

work.
Before this solution i need a lot of formulas to get the some results,

now
is very simple with your code.

It's possible get the msg results in a range of cells? I need the

values
number of counted "x" to calculate another things.
Sample: If a group of "x" = 7 then 7*another value

Thanks for your dedicated attention.I have excel experience but in vba

i'm
a
novice.
Excuse for my english.
Paulo Coelho





"Doug Glancy" wrote in message
...
woops, left in a couple of extra variables there, so for the sake of
neatness:

Dim r, x_range As Range
Dim i As Long
Dim msg As String

msg = ""

For Each r In Selection
If UCase(r) = "X" Then
If x_range Is Nothing Then
Set x_range = r
Else
Set x_range = Union(x_range, r)
End If
End If
Next r

For i = 1 To x_range.Areas.Count
msg = msg & "Group " & i & ":" & x_range.Areas(i).Cells.Count & "

x"
&
vbCrLf
Next i

MsgBox msg

End Sub

hth,

Doug

"JP" wrote in message
...
I need a formula or vba code to count how many groups of "X" values

and
how
many "X" in each group.
Sample:

a1
ah1
X X X X X X X A A A A X X X X X X B B B B B B X X X X X X X X X X X

X

Result i need with the code or formula
1 group 7 "x"
2 group 6 "x"
3 group 12"x"

Thanks for help
Paulo











  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Count each group of values

JP,

I think this does what you want. Let me know:

Sub test()

Dim r, x_range, result_range As Range
Dim i As Long
Dim msg As String

msg = ""
For Each r In Selection
If UCase(r) = "X" Then
If IsEmpty(x_range) Then
Set x_range = r
Else
Set x_range = Union(x_range, r)
End If
End If
Next r

If Not IsEmpty(x_range) Then
Set result_range = ActiveSheet.Range("A2")
With result_range
.Cells(0, 1) = "Group"
.Cells(0, 2) = "X count"
.Cells(0, 3) = "Hours"
For i = 1 To x_range.Areas.Count
.Cells(i, 1) = i
.Cells(i, 2) = x_range.Areas(i).Cells.Count
.Cells(i, 3).Formula = "=B" & Rows(i).Row + 1 & "*6"
Next i
End With
Else
MsgBox "No Xs in selected area"
End If

End Sub

Doug

"JP" wrote in message
...
Hello Doug

Thanks for your colaboration.
Another help please:

Itīs possible fix the results in a range of cells. I need the values

always
in some cells to make calculations.
Sample:A1:A7 groups; B1:B7 x counts and C1:C7 where y put my needed
calculations to be used by entire Worksheet functions
The ranges are flexible, another ranges be Ok.
A B C
Group X count Hours
1 5 30
2 4 24
3 10 48
4 2 12
5 3 18
6 4 24


Im a Health worker and this Worksheet is intended to count the lacks of my
personal group of workers in the hospital.
1 "x" = 1/5 of the week of work(30 hours) = 6
2 "x" = 2/5 .... =12
3 "x" = 3/5 .... =18
4 "x" = 4/5 .... =24
5, 6 or 7 "x" = 5/5 .... =30

Thanks for your attention
Best Regards
Paulo Coelho




"Doug Glancy" wrote in message
...
JP,

Here's one that puts the results in rows in the Column A below any other
data. If you need something else, let me know. I changed a couple of

other
things too:

Sub test()
Dim r, x_range, result_range As Range
Dim i As Long
Dim msg As String

msg = ""
For Each r In Selection
If UCase(r) = "X" Then
If IsEmpty(x_range) Then
Set x_range = r
Else
Set x_range = Union(x_range, r)
End If
End If
Next r

If Not IsEmpty(x_range) Then
Set result_range = ActiveSheet.Range("A" & ActiveSheet.Range("A" &
Rows.Count).End(xlUp).Row + 3)
With result_range
.Cells(0, 1) = "Group"
.Cells(0, 2) = "X count"
For i = 1 To x_range.Areas.Count
.Cells(i, 1) = i
.Cells(i, 2) = x_range.Areas(i).Cells.Count
Next i
End With
Else
MsgBox "No Xs in selected area"
End If

End Sub

hth,

Doug
"JP" wrote in message
...
Thank you very much for your help ACW.

Thank you very much "Doug Glancy", your solution is the best for my

work.
Before this solution i need a lot of formulas to get the some results,

now
is very simple with your code.

It's possible get the msg results in a range of cells? I need the

values
number of counted "x" to calculate another things.
Sample: If a group of "x" = 7 then 7*another value

Thanks for your dedicated attention.I have excel experience but in vba

i'm
a
novice.
Excuse for my english.
Paulo Coelho





"Doug Glancy" wrote in message
...
woops, left in a couple of extra variables there, so for the sake of
neatness:

Dim r, x_range As Range
Dim i As Long
Dim msg As String

msg = ""

For Each r In Selection
If UCase(r) = "X" Then
If x_range Is Nothing Then
Set x_range = r
Else
Set x_range = Union(x_range, r)
End If
End If
Next r

For i = 1 To x_range.Areas.Count
msg = msg & "Group " & i & ":" & x_range.Areas(i).Cells.Count &

"
x"
&
vbCrLf
Next i

MsgBox msg

End Sub

hth,

Doug

"JP" wrote in message
...
I need a formula or vba code to count how many groups of "X"

values
and
how
many "X" in each group.
Sample:

a1
ah1
X X X X X X X A A A A X X X X X X B B B B B B X X X X X X X X X X

X
X

Result i need with the code or formula
1 group 7 "x"
2 group 6 "x"
3 group 12"x"

Thanks for help
Paulo













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 count an age group Call me Ana, Ana Pego New Users to Excel 2 October 20th 08 12:43 AM
To count how many are in a certain age group LEG Excel Worksheet Functions 10 May 8th 08 06:23 AM
count group daniellchiu via OfficeKB.com Excel Discussion (Misc queries) 5 January 10th 08 04:35 AM
Count Distinct Values by Group Using Pivot Table (NM) MCP Excel Worksheet Functions 3 February 11th 05 09:22 PM
count a group of numbers but do not count duplicates Lisaml Excel Worksheet Functions 2 January 26th 05 11:19 PM


All times are GMT +1. The time now is 09:53 PM.

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"