Dim add As String
Dim dest As Range
Dim cfind As Range
Dim crit As Range
Dim i As Integer
Dim j As Integer
Dim rng As Range
Worksheets("sheet1").Activate
'Set rng = Range(Range("a1"), Cells(4, Columns.Count).End(xlToLeft))
'rng is your basic data consisting row2 upto row 4 or 8 with the last column in this case J
Set rng = Range(Range("a2"), Cells(8, Columns.Count).End(xlToLeft))
Set crit = Worksheets("sheet2").Range("a1")
'the unique values like high, low etc are pre-entered in row 12
line1:
With rng
Set cfind = .Find(what:=crit.Value, lookat:=xlWhole)
'it finds the first value equivalent to the value of range "crit" in the first case A12 value i.e. "high"
add = cfind.Address
'you must know the address of the first find of for example "high"
'because the find value in the next findnext is cricular.
'after finding all the value in rng it comes back to the firt high value
'so the looping in the find next should stop when it come back the first "high"
crit.Offset(1, 0) = cfind.Offset(-2, 0)
j = 1
i = 1
Do
On Error Resume Next
Set cfind = .FindNext(after:=cfind)
'findnext finds the next value of "high"
If cfind.Address = add Then
'if cfind is the first high value the looping has to stop and then
Set crit = crit.Offset(0, i)
'crit should go to the next value in row 12 i.e. "low"
If crit = "" Then GoTo line2
'when crit goes beyond the four values of row 12 the macro should stop
GoTo line1
' this is only a sort of looping
End If
crit.Offset(j + 1, 0) = cfind.Offset(-2, 0)
'this statement enters the first value of the name of the person of that category crit
j = j + 1
Loop While cfind.Address <> add
line2:
End With
MsgBox "macro over"
End Sub