-
1 Attachment(s)
How to arrange the order
If the "NO" of the B column first appears, the C column is 1, the second "NO" corresponds to the C column is 2, and so on, the first "YES" corresponding to the C column is 3, but The next "YES" is 1, the back of the "NO" is the C column corresponding from 1, I would like to ask how to write CODE
Attachment 19816
-
Hello
Try this code
Code:
Sub Test()
Dim c As Range
Dim i As Long
For Each c In Range("B2:B" & Cells(Rows.Count, 1).End(xlUp).Row)
If c = "No" Then
i = i + 1
c.Offset(, 1) = i
ElseIf c = "Yes" Then
c.Offset(, 1) = i + 1
i = 0
End If
Next c
End Sub
-
@ Yasser
Save typing and omit cycling through empty cells.
Code:
For Each c In Range("B:B").SpecialCells(2)
-
Thanks a lot my best tutor for this information
-
Thanks to the above two gentlemen's teachings
-
You're welcome my friend idnoidno. Glad we can offer some help
-
Mr. Yasser Khalil, thank you for your help, how will you deal with the problem when you meet the problem? English is not my native language, so my expression may not be right.
Someone at the forum told me to use the recording macro, but after I try, I do not feel a lot of help, can you give me some advice?
-
Mr. Yasser Khalil, thank you for your help, how will you deal with the problem when you meet the problem? English is not my native language, so my expression may not be right.
Someone at the forum told me to use the recording macro, but after I try, I do not feel a lot of help, can you give me some advice?
-
Using recording macro is useful but it will not be the best solution .. Sometimes if your recorded a task, this may produce a lot of lines while you can do that in one line. Try to follow the different threads and see the solutions and study them to develop yourself .. And I am still learning a lot
-
Mr. Yasser Khalil, thank you for your reply, do you have a website that you can recommend to me?
-
I recommend you WiseOwl Youtube channel ..