VBA Excel If without else error

Having an issue with a excel VBA module.
If then else statement is not working.
Please help.
Code is attached.
Thanks,
Eric
Do While ActiveCell <> ""  'Loops until the active cell is blank.
    
    If ActiveCell.Offset(0, -2).Value = "1320" Then _
      ActiveCell.Offset(0, 1).FormulaR1C1 = _
         "https://testlink1320=" & " " & _
    ActiveCell.Offset(0, 0)
      ActiveCell.Offset(1, 0).Select
    Else
      ActiveCell.Offset(0, 1).FormulaR1C1 = _
         "https://testlink1330=" & " " & _
         ActiveCell.Offset(0, 0)
      ActiveCell.Offset(1, 0).Select
    End If
    
   Loop

Open in new window

greeneeAsked:
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.

gtglonerCommented:
Try it now:
Sub macro()
Do While ActiveCell <> ""  'Loops until the active cell is blank.
     
    If ActiveCell.Offset(0, -2).Value = "1320" Then
      ActiveCell.Offset(0, 1).FormulaR1C1 = _
         "https://testlink1320=" & " " & _
    ActiveCell.Offset(0, 0)
      ActiveCell.Offset(1, 0).Select
    Else
      ActiveCell.Offset(0, 1).FormulaR1C1 = _
         "https://testlink1330=" & " " & _
         ActiveCell.Offset(0, 0)
      ActiveCell.Offset(1, 0).Select
    End If
     
   Loop


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
nutschCommented:
Is the 1320 value a text or a number. If it's a number you need to put =1320 without the inverted comas.

Also, since you have a if then else end if structure, you need to remove the underscore after the then on line 3

Thomas
0
jet46Commented:
What is the problem you are having?  Also, try taking out the _ at the end of the Then
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Ardhendu SarangiSr. Project ManagerCommented:
You have an error in your code.

"  If ActiveCell.Offset(0, -2).Value = "1320" Then _ " is incorrect.

Change this to "  If ActiveCell.Offset(0, -2).Value = "1320" Then"

See below,

- Ardhendu

    Do While ActiveCell <> ""  'Loops until the active cell is blank.
        If ActiveCell.Offset(0, -2).Value = "1320" Then
            ActiveCell.Offset(0, 1).FormulaR1C1 = _
            "https://testlink1320=" & " " & _
            ActiveCell.Offset(0, 0)
            ActiveCell.Offset(1, 0).Select
        Else
            ActiveCell.Offset(0, 1).FormulaR1C1 = _
            "https://testlink1330=" & " " & _
            ActiveCell.Offset(0, 0)
            ActiveCell.Offset(1, 0).Select
        End If
    Loop

Open in new window

0
Ardhendu SarangiSr. Project ManagerCommented:
hi Gtgloner,

I didn't see ur post. sorry abt that. You got it right first.

- Ardhendu
0
nutschCommented:
Eric, gtgloner got it first in the code he posted, even if he didn't detail the way he addressed your problem. I've requested reopening of the question should you want to reassign the points.

Thomas
0
gtglonerCommented:
Thanks, all.
0
byundtMechanical EngineerCommented:
I realize that the question has already been answered, but recorded macros are quite inefficient because of all the screen flickering and Select statements. I rewrote the macro to avoid both issues, so it should run faster and less annoyingly as a result.

Brad
Sub CellLooper()
Dim cel As Range, rg As Range
Dim sTestLink As String
Application.ScreenUpdating = False  'Eliminates screen flicker in Excel 2003 and earlier. Macro runs faster.
Set rg = Range("C2")    'First cell to be processed. Change this address to suit.
If rg.Offset(1, 0) <> "" Then Set rg = Range(rg, rg.End(xlDown))

For Each cel In rg.Cells
    sTestLink = IIf(cel.Offset(0, -2).Value = "1320", "1320=", "1330=")
    cel.Offset(0, 1).Formula = "https://testlink" & sTestLink & " " & cel
Next
Application.ScreenUpdating = True
End Sub

Open in new window

0
greeneeAuthor Commented:
sorry all, got the other email first for some reason.
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
Microsoft Excel

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.