Consulting

Results 1 to 4 of 4

Thread: If a condition is True how to add a number

  1. #1
    VBAX Regular
    Joined
    Jul 2008
    Posts
    43
    Location

    If a condition is True how to add a number

    I am having a bit of a memory block. I am sure I found the information once before, but now cannot remember how.
    I have a column of information and when items from it are in use, I have a checkbox column, a number column and a true/false column.
    When an item is checked it is in use and it is true.

    When I sort the information I would like to add a number in front of each item that is true and increase the number by one on each new item and then be able to sort the false items alphabetically below

    The sorting I can do, it is just the inserting the number and having it increase.

    I am still searching the site as I know I saw something similar before.

    Thanks in advance

  2. #2
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,198
    Location
    Can you not just sort the true/false column in descending order to get the same effect?
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

  3. #3
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,198
    Location
    If that is not an option then here is some code that may help...

    Sub Inc_Num()
        Dim EndRow As Long
        Dim rCell As Range
        Dim incNum As Long
        ' this assumes you want the incremented numbers in column "A" and
        ' that your true/false column is solid with data and is column "D".
        ' it starts at "D2".
        incNum = 1
        EndRow = Sheet1.Range("D" & Rows.Count).End(xlUp).Row
        For Each rCell In Sheet1.Range("D2:D" & EndRow).Cells
            If rCell.Value = True Then
                rCell.Offset(, -3).Value = incNum
                incNum = incNum + 1
           End If
        Next
    End Sub
    Hope this helps
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

  4. #4
    VBAX Regular
    Joined
    Jul 2008
    Posts
    43
    Location
    Thanks georgiboy.
    Yes that will possibly do it and while reading it I remembered "Autonumbering"

    Thanks

Posting Permissions

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