Disclaimer: I am not new to Excel but very new to VBA. I just read the "VBA for Dummies" book on Monday, and I am referencing another advanced VBA book so if my questions seem a bit basic, I hope you will be patient with me.
Question: In Excel 2010, how do I get checkbox information in a userform to enter into separate line items on a spreadsheet, while copying other identifying information from the form at the same time?
Let me explain:
I am creating a Userform to capture detailed customer information and move it into an Excel spreadsheet. This information will then be used in reports, pivot tables, etc.
Three of the fields in the form are text, and I have a frame containing several option buttons (users can only select one). The info gathered from this section of the form is entering into the spreadsheet as expected (thanks to some code I found either on YouTube or another blog) - sort of (that will be a separate question)
I have two other frames containing several check boxes. The end user should be able to select as many of these items as possible. However, only the first checkbox is entering into the spreadsheet.
What I would like to have happen:
I would like each checkbox item selected to enter in a separate line item in the spreadsheet, while also copying the identifying customer information from the other fields.
Here is the code I am using:
Private Sub btnEnterData_Click()
Dim Nextrow As String
'find the next empty row
Nextrow = Application.WorksheetFunction.CountA(Range("A:F"))
Cells(Nextrow, 1) = txtLegalEntityNumber.Text
Cells(Nextrow, 2) = txtLegalEntityName.Text
Cells(Nextrow, 3) = txtNumAcounts.Text
'Identify the Legal Entity Type
If LEButtonOption1 Then Cells(Nextrow, 4) = "Legal Entity Option 1"
If LEButtonOption2 Then Cells(Nextrow, 4) = "Legal Entity Option 2"
'Identify the Markets for this legal entity -
'These should be separate line items for each market and should copy the legal entity name, etc on each line
If Argentina Then Cells(Nextrow, 5) = "Argentina"
'If Australia Then Cells(Nextrow + 1, 5) = "Australia" << This is remarked out because I know it doesn't work but I am playing around to try an figure this out.
Here is what is appearing in the spreadsheet:
[TABLE="class: grid, width: 500"]
<TBODY>[TR]
[TD]Legal entity #[/TD]
[TD]Legal Entity Name[/TD]
[TD]# of Accounts[/TD]
[TD]Legal Entity Type[/TD]
[TD]# of Markets[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]ABC123[/TD]
[TD]20[/TD]
[TD]Option 1[/TD]
[TD]USA[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</TBODY>[/TABLE]
Here is what I would like to appear in the spreadsheet:
[TABLE="width: 500"]
<TBODY>[TR]
[TD]Legal Entity #[/TD]
[TD]Legal Entity Name[/TD]
[TD]# of Accounts[/TD]
[TD]Legal Entity Type[/TD]
[TD]# of Markets[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]ABC123[/TD]
[TD]20[/TD]
[TD]Option 1[/TD]
[TD]USA[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1 (copied)[/TD]
[TD]ABC123 (copied)[/TD]
[TD]20 (copied)[/TD]
[TD]Option 1 (copied)[/TD]
[TD]CAN[/TD]
[TD][/TD]
[/TR]
</TBODY>[/TABLE]
Question: In Excel 2010, how do I get checkbox information in a userform to enter into separate line items on a spreadsheet, while copying other identifying information from the form at the same time?
Let me explain:
I am creating a Userform to capture detailed customer information and move it into an Excel spreadsheet. This information will then be used in reports, pivot tables, etc.
Three of the fields in the form are text, and I have a frame containing several option buttons (users can only select one). The info gathered from this section of the form is entering into the spreadsheet as expected (thanks to some code I found either on YouTube or another blog) - sort of (that will be a separate question)
I have two other frames containing several check boxes. The end user should be able to select as many of these items as possible. However, only the first checkbox is entering into the spreadsheet.
What I would like to have happen:
I would like each checkbox item selected to enter in a separate line item in the spreadsheet, while also copying the identifying customer information from the other fields.
Here is the code I am using:
Private Sub btnEnterData_Click()
Dim Nextrow As String
'find the next empty row
Nextrow = Application.WorksheetFunction.CountA(Range("A:F"))
Cells(Nextrow, 1) = txtLegalEntityNumber.Text
Cells(Nextrow, 2) = txtLegalEntityName.Text
Cells(Nextrow, 3) = txtNumAcounts.Text
'Identify the Legal Entity Type
If LEButtonOption1 Then Cells(Nextrow, 4) = "Legal Entity Option 1"
If LEButtonOption2 Then Cells(Nextrow, 4) = "Legal Entity Option 2"
'Identify the Markets for this legal entity -
'These should be separate line items for each market and should copy the legal entity name, etc on each line
If Argentina Then Cells(Nextrow, 5) = "Argentina"
'If Australia Then Cells(Nextrow + 1, 5) = "Australia" << This is remarked out because I know it doesn't work but I am playing around to try an figure this out.
Here is what is appearing in the spreadsheet:
[TABLE="class: grid, width: 500"]
<TBODY>[TR]
[TD]Legal entity #[/TD]
[TD]Legal Entity Name[/TD]
[TD]# of Accounts[/TD]
[TD]Legal Entity Type[/TD]
[TD]# of Markets[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]ABC123[/TD]
[TD]20[/TD]
[TD]Option 1[/TD]
[TD]USA[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</TBODY>[/TABLE]
Here is what I would like to appear in the spreadsheet:
[TABLE="width: 500"]
<TBODY>[TR]
[TD]Legal Entity #[/TD]
[TD]Legal Entity Name[/TD]
[TD]# of Accounts[/TD]
[TD]Legal Entity Type[/TD]
[TD]# of Markets[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]ABC123[/TD]
[TD]20[/TD]
[TD]Option 1[/TD]
[TD]USA[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1 (copied)[/TD]
[TD]ABC123 (copied)[/TD]
[TD]20 (copied)[/TD]
[TD]Option 1 (copied)[/TD]
[TD]CAN[/TD]
[TD][/TD]
[/TR]
</TBODY>[/TABLE]