VBA Excel : Update values based on a numerical sequences

Hello experts,

I am looking for a VBA to update the various values if values of next column are not empty ex:

2015-09-03-14_54_20-Microsoft-Excel-.png
The macro should be automatically enter all the numeric sequences as of A2 : 1st Comparison, 2nd Comparison... if data reported in Column B is not empty.

If ordinal number are complicated to report It will be acceptable to report like this :

1 Comparison,  2 Comparison etc...


Thank y ou very much for your help.
LVL 1
LD16Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
I am not sure if I have understood your requirement correctly, but try this to see if this is what you are trying to achieve.
Sub InsertNumericSequence()
Dim lr As Long, n
Dim rng As Range, cell As Range

lr = Cells(Rows.Count, "B").End(xlUp).Row
Set rng = Range("B3:B" & lr)

For Each cell In rng
    If cell <> "" Then
        n = WorksheetFunction.CountA(Range(Cells(3, "B"), Cells(cell.Row, "B")))
        Select Case Len(n)
            Case 1
                Select Case n
                    Case 1
                        cell.Offset(0, -1) = "1st Comparison"
                    Case 2
                        cell.Offset(0, -1) = "2nd Comparison"
                    Case 3
                        cell.Offset(0, -1) = "3rd Comparison"
                    Case Else
                        cell.Offset(0, -1) = n & "th Comparison"
                End Select
            Case Else
                If Right(n, 2) >= 11 And Right(n, 2) <= 20 Then
                    cell.Offset(0, -1) = n & "th Comparison"
                Else
                    Select Case Right(n, 1)
                        Case 1
                            cell.Offset(0, -1) = n & "st Comparison"
                        Case 2
                            cell.Offset(0, -1) = n & "nd Comparison"
                        Case 3
                            cell.Offset(0, -1) = n & "rd Comparison"
                        Case Else
                            cell.Offset(0, -1) = n & "th Comparison"
                    End Select
                End If
        End Select
    End If
Next cell

End Sub

Open in new window

0
LD16Author Commented:
Working perfectly.

I forgot to specify the following requirement: bold all the values reported in column A. Is there a way to integrate this in your previous code?
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Okay try this.....

Sub InsertNumericSequence()
Dim lr As Long, n
Dim rng As Range, cell As Range

lr = Cells(Rows.Count, "B").End(xlUp).Row
Set rng = Range("B3:B" & lr)
For Each cell In rng
    If cell <> "" Then
        n = WorksheetFunction.CountA(Range(Cells(3, "B"), Cells(cell.Row, "B")))
        Select Case Len(n)
            Case 1
                Select Case n
                    Case 1
                        cell.Offset(0, -1) = "1st Comparison"
                    Case 2
                        cell.Offset(0, -1) = "2nd Comparison"
                    Case 3
                        cell.Offset(0, -1) = "3rd Comparison"
                    Case Else
                        cell.Offset(0, -1) = n & "th Comparison"
                End Select
            Case Else
                If Right(n, 2) >= 11 And Right(n, 2) <= 20 Then
                    cell.Offset(0, -1) = n & "th Comparison"
                Else
                    Select Case Right(n, 1)
                        Case 1
                            cell.Offset(0, -1) = n & "st Comparison"
                        Case 2
                            cell.Offset(0, -1) = n & "nd Comparison"
                        Case 3
                            cell.Offset(0, -1) = n & "rd Comparison"
                        Case Else
                            cell.Offset(0, -1) = n & "th Comparison"
                    End Select
                End If
        End Select
    End If
Next cell
lr = Cells(Rows.Count, "A").End(xlUp).Row
Range("A3:A" & lr).Font.Bold = True
MsgBox "Sequence have been generated successfully.", vbInformation
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

LD16Author Commented:
Tested and it works!
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Glad to know that. :)
I think you forgot to mark your question Solved by selecting the accepted solution. Please find some time to do that. :)
0
LD16Author Commented:
You are right. Sorry for that.
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Never mind. :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.