Else without if Error, but I have an if?

vbaNumpty

Board Regular
Joined
Apr 20, 2021
Messages
171
Office Version
  1. 365
Platform
  1. Windows
I am getting an else without if error, but I only have one if. Can anyone tell me what I am missing here?

VBA Code:
    If Me.ComboBox1.Value > "" And Me.departure1.Value > "" Then
    
        Set myArray = ufd.Range("Truck_1")
        
        For z = 1 To i
            
            n = 0
            Set addMe = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
            addMe.Value = z
            addMe.Offset(n, 1).Value = myArray(z, 2)
            addMe.Offset(n, 2).Value = myArray(z, 4)
            
            addMe.HorizontalAlignment = xlCenter
            addMe.Offset(n, 2).HorizontalAlignment = xlCenter
             
        Next z
                 
        Set addMe = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(-z + 2, 0)
        addMe.Offset(0, 3).Value = ComboBox1.Value
        addMe.Offset(0, 4).Value = departure1.Value
        addMe.Offset(i, 0).Value = "helloworld"
        
        'black line
        With addMe.Offset(i, 0).EntireRow.Interior
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            .ThemeColor = xlThemeColorLight1
        End With
        
        addMe.Offset(0, 3).Resize(z - 1).Merge
        With addMe.Offset(0, 3)
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .MergeCells = True
            .WrapText = True
        End With
        
        addMe.Offset(0, 4).Resize(z - 1).Merge
        With addMe.Offset(0, 4)
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
            .MergeCells = True
            .WrapText = True
        End With
        
        With addMe.Resize(z - 1, 5).Borders.LineStyle = xlContinuous
            
    Else
    
        MsgBox "Please make sure to select a first truck and departure time.", vbOKOnly + vbInformation, "Error"
        Exit Sub
        
    End If
    

End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
You need to remove the With from this line
VBA Code:
   With addMe.Resize(z - 1, 5).Borders.LineStyle = xlContinuous
 
Upvote 0
Solution

Forum statistics

Threads
1,223,275
Messages
6,171,122
Members
452,381
Latest member
Nova88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top