I have some data in column A like this
ColA
Z
A
Z
A
Z
A
A
B
B
B
Z
B
B
Z
C
C
C
D
D
I want to print in column B
"0" if cell in A = "Z"
empty when cell in A is empty
When a group begins for example with letter A, then all next A's should be marked with 1.
When a next group begins, i.e. with letter B, then mark all following B's with 2,
When begins a new group i.e with letter C, mark with value 1 again and so on.
the values in column A are not letters in alphabetical sequence. Is only an example. I only know the value of "Z", the groups could have any string
This is, alternate assigning values 1 and 2 for each new group. I hope make sense.
This is my current code
Sub t1()
Dim dict As Object
Set dict = CreateObject("Scripting.Dictionary")
For i = 1 To 24
If Cells(i, "A") = "Z" Then
Cells(i, "B") = "0"
ElseIf Cells(i, "A") <> "Z" And Cells(i, "A") <> "" Then
counter = counter + 1
dict.Add Key:=Cells(i, "A"), Item:=1
If Not dict.Exists(Cells(i, "A")) Then
If counter Mod 2 = 1 Then
Cells(i, "B") = "1"
Else
Cells(i, "B") = "2"
End If
End If
End If
Next
End Sub
My curent output in column B and my expected output in Column Cells
ColA ColB ColC
Z 0 0
A 1 1
Z 0 0
A 2 1
Z 0 0
A 1 1
A 2 1
B 1 2
B 2 2
B 1 2
Z 0 0
B 2 2
B 1 2
Z 0 0
C 2 1
C 1 1
C 2 1
D 1 2
D 2 2
Maybe someone could help me. Thanks