I have got some code here, but I get the following error:
Run-time error 1004
Application-defined or object-defined error
So hopefully someone can help me figure out what I am doing wrong. Still very new to all of this...
What I want my userform to do
I have a userform which is two pages, it uses multipage.
I want all my users to fill in details on the first page, called 'Main'. On this form is an option-button question: "Did the customer ask about a product today?".
If the answer to this question is 'no', the form should end after the command button is clicked, sending the relevant info to the worksheet.
If the answer to this question is 'yes', the form should automatically send the user to the 'Extra' page. The user completes this page, hits the command button on this second page, and the form will send the info from both pages into the same row of the worksheet.
My Code
For the command button on the 'Main' page
Private Sub CommandButton1_Click()
Dim emptyRow As Long
Dim closeForm As Boolean
'The form should close, unless ProductEnquiryYes is true
closeForm = True
'Determine emptyRow
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
'Did customer ask about product?
If ProductEnquiryYes.Value = True Then
Me.MultiPage1.Value = 1
closeForm = False
Cells(emptyRow, 20).Value = 1
End If
If ProductEnquiryNo.Value = True Then
Cells(emptyRow, 21).Value = 1
End If
'Balance Enquiry
If BalanceEnquiry.Value = True Then
Cells(emptyRow, 23).Value = 1
End If
'Close Userform
If closeForm Then Unload Me
End Sub
For the command button on the 'Extra' page
Private Sub CommandButton2_Click()
'If this checkbox is True, send value of 1 to the worksheet
If CAOpen.Value = True Then
Cells(emptyRow, 63).Value = 1
End If
Unload Me
End Sub
The command button works for the first page, and is returning the values correctly into the worksheet. However, the command button on the second page is not correct, and I do not know why. It's probably something obvious, so please forgive me.
When I hit debug, it is specifically this line that is highlighted in yellow:
Cells(emptyRow, 63).Value = 1
Thanks for the help!!