View Full Version : [SOLVED:] How to arrange the order
idnoidno
07-20-2017, 01:43 AM
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
19816
YasserKhalil
07-20-2017, 01:56 AM
Hello
Try this 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
mdmackillop
07-20-2017, 02:55 AM
@ Yasser
Save typing and omit cycling through empty cells.
For Each c In Range("B:B").SpecialCells(2)
YasserKhalil
07-20-2017, 03:11 AM
Thanks a lot my best tutor for this information
idnoidno
07-20-2017, 04:58 PM
Thanks to the above two gentlemen's teachings
YasserKhalil
07-21-2017, 12:20 AM
You're welcome my friend idnoidno. Glad we can offer some help
idnoidno
07-21-2017, 12:44 AM
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?
idnoidno
07-21-2017, 12:58 AM
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?
YasserKhalil
07-21-2017, 01:02 AM
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
idnoidno
07-21-2017, 01:20 AM
Mr. Yasser Khalil, thank you for your reply, do you have a website that you can recommend to me?
YasserKhalil
07-21-2017, 01:23 AM
I recommend you WiseOwl Youtube channel ..
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.