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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
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,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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