PDA

View Full Version : Solved: If a condition is True how to add a number



kisinana
04-20-2009, 10:01 PM
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

georgiboy
04-20-2009, 10:07 PM
Can you not just sort the true/false column in descending order to get the same effect?

georgiboy
04-20-2009, 10:18 PM
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

kisinana
04-20-2009, 10:25 PM
Thanks georgiboy.
Yes that will possibly do it and while reading it I remembered "Autonumbering"

Thanks