Hi there,
I tried reading a few different threads with similar error messages to try to resolve this, but I'm evidently missing something. I should preface this by saying I'm new to macros and VBA (using various examples and tutorials to Frankenstein my way to something functional).
What it should do:
When the UserForm is called (either upon opening the document or pressing a button to restart the process), a form with 3 comboboxes and two checboxes appears. Comboboxes 1 and 2 are statically populated from a reference data sheet in the workbook. If Combobox 1's index is the second value, then combobox 3 uses the value of combobox 2 to populate from one of three tables in the reference data sheet. This is where the error is occurring. The checkboxes set cell values in the reference data sheet to tell it to bypass restrictions set on matching data for the workbook's function.
What I have put together:
The UserForm initializes fine and comes up with a temporary button I put in for testing. The error occurs when I change the value of the aShift combobox (combobox 2 from the above explanation). I've used F8 to step through, and it gets to the line:
before giving the error message:
from my currently limited understanding of VBA, it *should* be working. Please tell me it's not the VBA equivalent of forgetting ";" or "}" in PHP scripting.
I tried reading a few different threads with similar error messages to try to resolve this, but I'm evidently missing something. I should preface this by saying I'm new to macros and VBA (using various examples and tutorials to Frankenstein my way to something functional).
What it should do:
When the UserForm is called (either upon opening the document or pressing a button to restart the process), a form with 3 comboboxes and two checboxes appears. Comboboxes 1 and 2 are statically populated from a reference data sheet in the workbook. If Combobox 1's index is the second value, then combobox 3 uses the value of combobox 2 to populate from one of three tables in the reference data sheet. This is where the error is occurring. The checkboxes set cell values in the reference data sheet to tell it to bypass restrictions set on matching data for the workbook's function.
What I have put together:
Code:
Private Sub aShift_Change()
'set variables
Dim in1 As Integer
Dim in2 As Integer
Dim sheet As Worksheet
Dim cPerson As Range
Set in1 = Me.aType.ListIndex
Set in2 = Me.aShift.ListIndex
Set sheet = Worksheets("Reference Data")
'check audit type
If in1 = 1 Then
Me.aPerson.Clear
'select shift to populate with
Select Case in2
Case Is = 0
For Each cPerson In sheet.Range("First")
With Me.aPerson
.AddItem cPerson.Value
End With
Next cPerson
Case Is = 1
For Each cPerson In sheet.Range("Second")
With Me.aPerson
.AddItem cPerson.Value
End With
Next cPerson
Case Is = 2
For Each cPerson In sheet.Range("Third")
With Me.aPerson
.AddItem cPerson.Value
End With
Next cPerson
End Select
Else
Me.aPerson.Clear
End If
End Sub
Private Sub runAudit_Click()
'set variables
Dim sheet As Worksheet
Set sheet = Worksheets("Reference Data")
'Set selections cells
sheet.Range("B11").Value = aType.Value
sheet.Range("B12").Value = aShift.Value
If Me.aType.ListIndex = 0 Then
sheet.Range("B13").Value = "N/A"
Else
sheet.Range("B13").Value = aPerson.Value
End If
End Sub
Private Sub UserForm_Initialize()
With Me
.addDownstream.Enabled = True
.addUpstream.Enabled = True
.aType.Enabled = True
.aPerson.Enabled = True
.aShift.Enabled = True
.runAudit.Enabled = True
.Label1.Enabled = True
.Label2.Enabled = True
.Label3.Enabled = True
.Label4.Enabled = True
.Enabled = True
End With
'set variables
Dim cType As Range
Dim cShift As Range
Dim sheet As Worksheet
Set sheet = Worksheets("Reference Data")
'populate type
For Each cType In sheet.Range("Type")
With Me.aType
.AddItem cType.Value
End With
Next cType
'populate shift
For Each cShift In sheet.Range("Shift")
With Me.aShift
.AddItem cShift.Value
End With
Next cShift
End Sub
The UserForm initializes fine and comes up with a temporary button I put in for testing. The error occurs when I change the value of the aShift combobox (combobox 2 from the above explanation). I've used F8 to step through, and it gets to the line:
Code:
Private Sub aShift_Change()
before giving the error message:
Compile error:
Object required.
from my currently limited understanding of VBA, it *should* be working. Please tell me it's not the VBA equivalent of forgetting ";" or "}" in PHP scripting.