0

Noob started coding 2 days ago. I need to combine these two if statements so only one IF works at a time. Every time I attempt to add Else, Else If or even End If I receive errors such as Else without IF. Nothing I do seems to work. Thank you for your help.

If Cells(i, 15).Value = "address" Then Result = "Return"
    ActiveSheet.Cells(i, 27).Select
    ActiveCell.Value = Result
    
    Cells(i, 28).Value = Cells(i, 8).Value + Cells(i, 26).Value


If Cells(i, 15).Value <> "address" Then Result = "Pickup"
    ActiveSheet.Cells(i, 27).Select
    ActiveCell.Value = Result
    
    Cells(i, 28).Value = Cells(i, 8).Value - Cells(i, 26).Value
  • 1
    You need to move `Result = "Return"` and `Result = "Pickup"` to new lines. – BigBen Nov 25 '20 at 02:21
  • 1
    It may be worth reading the [documentation](https://learn.microsoft.com/en-us/office/vba/language/concepts/getting-started/using-ifthenelse-statements), which discusses both the single- and multi-line syntax. – BigBen Nov 25 '20 at 02:25
  • Really, that's all I had to do. I made a new line after "Then" and error went away. I now have "ElseIF" in the place of the 2nd IF statement and End IF at the end. It doesn't make much sense but ok. Thank you for the help both of you. – Jonathan Blaine Nov 25 '20 at 03:19
  • 1
    There are two ways to use `If` - single-line syntax, and multi-line syntax. The docs and the linked question provide more context. – BigBen Nov 25 '20 at 03:20
  • Okay. I will look into single and multi-line and figure out the difference. – Jonathan Blaine Nov 25 '20 at 03:23

0 Answers0