View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default LOOPING BUT THE MARKS ARE NOT IN SEQUENTIAL ORDER

written assuming the J's are in column 1.

Sub LoopJs()
Dim jlist As New Collection
Dim rng As Range, cnt As Long
Dim sAddr As String, s As String
Dim itm As Variant
Set rng = Columns(1).Find(What:="J*", _
After:=Range("A65536").End(xlUp)(2), _
LookIn:=xlFormulas, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not rng Is Nothing Then
sAddr = rng.Address
Do
On Error Resume Next
jlist.Add rng.Value, rng.Text
On Error GoTo 0
Set rng = Columns(1).FindNext(rng)
Loop While rng.Address < sAddr
s = ""
For Each itm In jlist
cnt = Application.CountIf(Columns(1), itm)
s = s & itm & ": " & cnt & vbNewLine
Next
MsgBox s
Else
MsgBox "No J's found"
End If
End Sub

Modify to fit your layout and achieve your required results.

--
Regards,
Tom Ogilvy


" wrote:


Hello:

In my spreadsheet I have many members that i am designing. each member
has a name that starts with a "J". For example J1, J2, J3....... i
might do several checks on each member, therfore the marks will be
placed in one of the sheets named "QDSsheet" starting in cell "A3" as
follows:
I wont know how many checks per mark. meaning i might have 4 J1's 0R
100 J1's, and the same goes for other marks. right now my code is set
up ok using "FOR... NEXT" provided the marks are in numeric
sequential order( J1....., J2.....,J3,.....,J4,.....,it will recognize
how many J1 is there or how many J2 is there so it loops by increment
of one. I would like you to tell me how to write the code so that it
loops through all the marks regardless of the order and what the number
or string after the J as shown below. Thanks!

Marks
J1
J1
J1
J1
J10
J10
J11
J12
J12A
J18
J18
J18
J17A
J17A
J17A
J17B
J15C