Consulting

Results 1 to 11 of 11

Thread: How to arrange the order

  1. #1

    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

    SEQ.xlsx

  2. #2
    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

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    @ Yasser
    Save typing and omit cycling through empty cells.
    For Each c In Range("B:B").SpecialCells(2)
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    Thanks a lot my best tutor for this information

  5. #5
    Thanks to the above two gentlemen's teachings

  6. #6
    You're welcome my friend idnoidno. Glad we can offer some help

  7. #7
    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?

  8. #8
    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?

  9. #9
    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

  10. #10
    Mr. Yasser Khalil, thank you for your reply, do you have a website that you can recommend to me?

  11. #11
    I recommend you WiseOwl Youtube channel ..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •