Looping if condition

Hi Experts,

I have the following VBA code and need to simplify.

If Sheets("Compiling").Range("B1").Value = "SS_001_CER_018_001" Then
                nodX.Expanded = True
            End If
            If Sheets("Compiling").Range("B1").Value = "SS_001_CER_018_002" Then
                nodX.Expanded = True
            End If
            If Sheets("Compiling").Range("B1").Value = "SS_001_CER_018_003" Then
                nodX.Expanded = True
            End If
            If Sheets("Compiling").Range("B1").Value = "SS_001_CER_018_004" Then
                nodX.Expanded = True
            End If
            If Sheets("Compiling").Range("B1").Value = "SS_001_CER_018_005" Then
                nodX.Expanded = True
            End If
            If Sheets("Compiling").Range("B1").Value = "SS_001_CER_018_006" Then
                nodX.Expanded = True
            End If
            If Sheets("Compiling").Range("B1").Value = "SS_001_CER_018_007" Then
                nodX.Expanded = True
            End If
            If Sheets("Compiling").Range("B1").Value = "SS_001_CER_018_008" Then
                nodX.Expanded = True
            End If
            If Sheets("Compiling").Range("B1").Value = "SS_001_CER_018_009" Then
                nodX.Expanded = True
            End If
            If Sheets("Compiling").Range("B1").Value = "SS_001_CER_018_010" Then
                nodX.Expanded = True
            End If
            If Sheets("Compiling").Range("B1").Value = "SS_001_CER_018_011" Then
                nodX.Expanded = True
            End If
            If Sheets("Compiling").Range("B1").Value = "SS_001_CER_018_012" Then
                nodX.Expanded = True
            End If
 

my Sheets("Compiling").Range("B1").Value is same "SS_001_CER_018_" except the last three digits (001) and it goes till 012 and I need put them in a loop or simplify this code as soon as possible.
Can you please help me out simplifying this code?

Tpaul_10Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
Something like...

    Dim i As Integer
    For i = 1 To 12
        If Sheets("Compiling").Range("B1").Value = "SS_001_CER_018_" & Format(i, "000") Then
            nodX.Expanded = True
            Exit For
        End If
    Next i
Jim HornMicrosoft SQL Server Data DudeCommented:
For starters....

Select Case Sheets("Compiling").Range("B1").Value
   Case  "SS_001_CER_018_001", "keep adding your criteria here", "and here", "and here too"
      nodX.Expanded = True
   Case Else
      nodX.Expanded = False
End Select
EDDYKTCommented:
Or


Dim i as integer

i = CInt(Right(Sheets("Compiling").Range("B1").Value , 3))
if (i > 0 and i < 13) then nodX.Expanded = True

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
aikimarkCommented:
1. I wish I could have used the VB Like operator, but it wouldn't work. :-(

2. You can use the regular expression class if you add the scripting runtime reference to your project.

3. Simplest solution is

Select Case Sheets("Compiling").Range("B1").Value
   Case  "SS_001_CER_018_001" To "SS_001_CER_018_012"
      nodX.Expanded = True
End Select
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.