For without Next error

harimao

New Member
Joined
Oct 23, 2020
Messages
4
Office Version
  1. 2016
  2. 2013
  3. 2010
  4. 2007
Platform
  1. Windows
  2. MacOS
as I still newbie for VBA, i created save button but after click it then came these error, highlight last End Sub

VBA Code:
Private Sub CommandButton1_Click()
If TextBox1.Text <> Empty And TextBox2.Text <> Empty And TextBox4.Text <> Empty Then
If Empty And TextBox5.Text <> Empty And TextBox6.Text <> Empty Then
If Empty And TextBox7.Text <> Empty And TextBox8.Text <> Empty Then
If Empty And TextBox9.Text <> Empty And TextBox10.Text <> Empty Then
If Empty And TextBox11.Text <> Empty And TextBox12.Text <> Empty And TextBox13.Text <> Empty Then
If Empty And TextBox14.Text <> Empty And TextBox15.Text <> Empty And TextBox16.Text <> Empty Then
If Empty And TextBox17.Text <> Empty And TextBox18.Text <> Empty And TextBox19.Text <> Empty Then
If Empty And TextBox20.Text <> Empty And TextBox21.Text <> Empty And TextBox22.Text <> Empty Then
If Empty And TextBox23.Text <> Empty And TextBox24.Text <> Empty And TextBox25.Text <> Empty Then
If Empty And TextBox26.Text <> Empty And TextBox27.Text <> Empty And TextBox28.Text <> Empty Then
If Empty And TextBox29.Text <> Empty And TextBox30.Text <> Empty And TextBox31.Text <> ComboBox1.Text <> Empty Then
TextBox3 = Sheets("Sheet1").Range("a65536").End(3).Value + 1
Else
    MsgBox "Missing Information", vbExclamation
    CommandButton2_Click
        Exit Sub
End If
With Sheets("Sheet1")
For Each bul In Sheets("Sheet1").Range("b2:b" & Range("b65536").End(3).Row)
    If bul = ComboBox1 Then
    Label5.Visible = True
        Exit Sub
    End If
Next bul
For Each bul In .Range("b2:b" & Range("b65536").End(3).Row)
    If bul = ComboBox1 Then
        bul.Offset(i, -1).Activate
        bul.Offset(i, 1) = TextBox1
        bul.Offset(i, 2) = TextBox2
        bul.Offset(i, 3) = TextBox4
        bul.Offset(i, 4) = TextBox5
        bul.Offset(i, 5) = TextBox6
        bul.Offset(i, 6) = TextBox7
        bul.Offset(i, 7) = TextBox8
        bul.Offset(i, 8) = TextBox9
        bul.Offset(i, 9) = TextBox10
        bul.Offset(i, 10) = TextBox11
        bul.Offset(i, 11) = TextBox12
        bul.Offset(i, 12) = TextBox13
        bul.Offset(i, 13) = TextBox14
        bul.Offset(i, 14) = TextBox15
        bul.Offset(i, 15) = TextBox16
        bul.Offset(i, 16) = TextBox17
        bul.Offset(i, 17) = TextBox18
        bul.Offset(i, 18) = TextBox19
        bul.Offset(i, 19) = TextBox20
        bul.Offset(i, 20) = TextBox21
        bul.Offset(i, 21) = TextBox22
        bul.Offset(i, 22) = TextBox23
        bul.Offset(i, 23) = TextBox24
        bul.Offset(i, 24) = TextBox25
        bul.Offset(i, 25) = TextBox26
        bul.Offset(i, 26) = TextBox27
        bul.Offset(i, 27) = TextBox28
        bul.Offset(i, 28) = TextBox29
        bul.Offset(i, 29) = TextBox30
        bul.Offset(i, 30) = TextBox31
        bul.Offset(i, -1) = TextBox3
        Exit For
    Else
        .Range("a65536").End(3).Offset(1, 0) = .Range("a65536").End(3) + 1
        .Range("a65536").End(3).Offset(0, 1) = ComboBox1
        .Range("a65536").End(3).Offset(0, 2) = TextBox1
        .Range("a65536").End(3).Offset(0, 3) = TextBox2
        .Range("a65536").End(3).Offset(0, 4) = TextBox4
        .Range("a65536").End(3).Offset(0, 5) = TextBox5
        .Range("a65536").End(3).Offset(0, 6) = TextBox6
        .Range("a65536").End(3).Offset(0, 7) = TextBox7
        .Range("a65536").End(3).Offset(0, 8) = TextBox8
        .Range("a65536").End(3).Offset(0, 9) = TextBox9
        .Range("a65536").End(3).Offset(0, 10) = TextBox10
        .Range("a65536").End(3).Offset(0, 11) = TextBox11
        .Range("a65536").End(3).Offset(0, 12) = TextBox12
        .Range("a65536").End(3).Offset(0, 13) = TextBox13
        .Range("a65536").End(3).Offset(0, 14) = TextBox14
        .Range("a65536").End(3).Offset(0, 15) = TextBox15
        .Range("a65536").End(3).Offset(0, 16) = TextBox16
        .Range("a65536").End(3).Offset(0, 17) = TextBox17
        .Range("a65536").End(3).Offset(0, 18) = TextBox18
        .Range("a65536").End(3).Offset(0, 19) = TextBox19
        .Range("a65536").End(3).Offset(0, 20) = TextBox20
        .Range("a65536").End(3).Offset(0, 21) = TextBox21
        .Range("a65536").End(3).Offset(0, 22) = TextBox22
        .Range("a65536").End(3).Offset(0, 23) = TextBox23
        .Range("a65536").End(3).Offset(0, 24) = TextBox24
        .Range("a65536").End(3).Offset(0, 25) = TextBox25
        .Range("a65536").End(3).Offset(0, 26) = TextBox26
        .Range("a65536").End(3).Offset(0, 27) = TextBox27
        .Range("a65536").End(3).Offset(0, 28) = TextBox28
        .Range("a65536").End(3).Offset(0, 29) = TextBox29
        .Range("a65536").End(3).Offset(0, 30) = TextBox30
        .Range("a65536").End(3).Offset(0, 31) = TextBox31
        CommandButton2_Click
        ComboBox1.Clear
        UserForm_Initialize
        Exit For
    End If
End Sub
 
Last edited by a moderator:

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
i believe you may need a "Next" statement between the End If & End Sub at the bottom of your routine.


Exit For
End If
Next
End Sub
 
Upvote 0
Its likely after solving the next issue, you will receive an If without End If issue, this i believe is down to the start code, where you have a number of if statements with only 1 end if: a few more may be required as below

______________________________________________________________________________________
MsgBox "Missing Information", vbExclamation
CommandButton2_Click
Exit Sub
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If

End If

With Sheets("Sheet1")
For Each bul In Sheets("Sheet1").Range("b2:b" & Range("b65536").End(3).Row)
________________________________________________________________________________________



you could also shorten your code with some for next statements like below

VBA Code:
For Each bul In Range("b2:b" & Range("b65536").End(3).Row)
If bul = ComboBox1 Then
bul.Offset(i, -1).Activate
    Dim j As Integer, tb As Integer: tb = 1
For j = 1 To 30
    bul.Offsett(i, j) = TextBox & tb
    tb = tb + 1
Next j
bul.Offset(i, -1) = TextBox3
Exit For

Else
.Range("a65536").End(3).Offset(1, 0) = Range("a65536").End(xlToRight) + 1
.Range("a65536").End(3).Offset(0, 1) = ComboBox1


tb = 1
For j = 2 To 31
    .Range("a65536").End(3).Offset(0, j) = TextBox & tb
    tb = tb + 1
Next j

CommandButton2_Click
ComboBox1.Clear
 
Upvote 0
With Sheets("Sheet1") <--This line means you need to add an End With
 
Upvote 0
Solution
With Sheets("Sheet1") <--This line means you need to add an End With
Ok, solved and working with 10 End If that u recommended, the shorten way still under testing..
Anyway thanks for your's hand!
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

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