Hi there everyone,
I've recently been trying to learn some basic vba to help with duties at my work. I've been following some youtube videos and came into a problem i cant seem to find the answer for. I keep getting a 'next without for' compile error. I know its because i was following youtube videos that weren't using option explicit and i am. So i think it has to do with not defining the variables properly. I've attempted a few different things that i've seen suggested on here, but its still giving me trouble.
here is my code;
Thanks very much for any help/suggestions people can provide.
I've recently been trying to learn some basic vba to help with duties at my work. I've been following some youtube videos and came into a problem i cant seem to find the answer for. I keep getting a 'next without for' compile error. I know its because i was following youtube videos that weren't using option explicit and i am. So i think it has to do with not defining the variables properly. I've attempted a few different things that i've seen suggested on here, but its still giving me trouble.
here is my code;
Code:
Option Explicit
Private Sub btnAdd_Click()
Dim ws As Worksheet
Set ws = Worksheets("Overstocks")
Dim i As Variant
Dim newRow As Long
newRow = Application.WorksheetFunction.CountA(ws.Range("A:A")) + 1
ws.Cells(newRow, 1).Value = Me.txtBrand.Value
ws.Cells(newRow, 2).Value = Me.cbCategory.Value
ws.Cells(newRow, 3).Value = Me.txtQuantity.Value
If opYes.Value = True Then
ws.Cells(newRow, 4).Value = "Yes"
Else:
ws.Cells(newRow, 4).Value = "No"
End If
Next i
Clear_Form
End Sub
Sub Clear_Form()
For Each Control In Me.Controls
Select Case TypeName(ctrl)
Case "TextBox"
ctrl.Text = ""
Case "ComboBox"
ctrl.ListIndex = -1
Case "OptionButton"
ctrl.Value = False
End If
Next i
End Select
Next
End Sub
Private Sub btnClose_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
With cbCategory
.AddItem "Beer"
.AddItem "Ready To Drink"
.AddItem "Spirits"
.AddItem "Wine - Red"
.AddItem "Wine - Sparkling"
.AddItem "Wine - White"
End With
End Sub
Thanks very much for any help/suggestions people can provide.