Please can you advise on my code

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Hi,

Code in use as supplide.

I complete the userform but when i press the command button to send the values to the worksheet i now see End If Without Block If.


VBA Code:
Private Sub CommandButton1_Click()
    Dim i As Integer
    Dim X As Long
    Dim ControlsArr(1 To 8) As Variant
    
    
    For i = 1 To 8
        If i > 2 Then
            With Me.Controls("ComboBox" & i)
                If .ListIndex = -1 Then
                    MsgBox "YOU MUST COMPLETE ALL FIELDS", vbCritical, "MC LIST TRANSFER"
                    TextBox1.SetFocus
                    Exit Sub
                Else
                    ControlsArr(i) = .Value
                End If
            End With
        Else
            ControlsArr(i) = Me.Controls("TextBox" & i).Value
        End If
    Next i
        
        Application.ScreenUpdating = False
        
        With ThisWorkbook.Worksheets("MC LIST")
            .Range("A8").EntireRow.Insert Shift:=xlDown
            .Range("A8:I8").Borders.Weight = xlThin
            .Cells(8, 1).Resize(, UBound(ControlsArr)).Value = ControlsArr
            

        End With
        Range("B8").Select
        Range("A8").Select
        ActiveWorkbook.Save

        Application.ScreenUpdating = True
        MsgBox "Database Has Been Updated", vbInformation, "SUCCESSFUL MESSAGE"
       With ThisWorkbook.Worksheets("MC LIST")
       If .AutoFilterMode Then .AutoFilterMode = False
            X = .Cells(.Rows.Count, 1).End(xlUp).Row
            .Range("A7:I" & X).Sort Key1:=Range("A8"), Order1:=xlAscending, Header:=xlGuess
            .Range("A8").Select
        End With
        End If
        Unload McListForm
End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
There isn't an If to go with the End If in red below.

Rich (BB code):
    Application.ScreenUpdating = True
    MsgBox "Database Has Been Updated", vbInformation, "SUCCESSFUL MESSAGE"
    With ThisWorkbook.Worksheets("MC LIST")
        If .AutoFilterMode Then .AutoFilterMode = False
        X = .Cells(.Rows.Count, 1).End(xlUp).Row
        .Range("A7:I" & X).Sort Key1:=Range("A8"), Order1:=xlAscending, Header:=xlGuess
        .Range("A8").Select
    End With
End If
Unload McListForm
End Sub
 
Last edited:
Upvote 0
Isnt this it ?

VBA Code:
If .AutoFilterMode Then .AutoFilterMode = False
 
Upvote 0
Isnt this it ?

VBA Code:
If .AutoFilterMode Then .AutoFilterMode = False
No, the If statement there has a start and finish (the .AutoFilterMode = False finishes it ).
The End If needs deleting.
 
Upvote 0

Forum statistics

Threads
1,214,927
Messages
6,122,309
Members
449,080
Latest member
jmsotelo

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