copy data from userform to multiple sheets based on checkbox selection

Starchaser

New Member
Joined
Mar 4, 2017
Messages
8
Hi everybody,

I want to copy selected data out of a listbox to different other sheets based on a selection of multiple checkboxes
I've already created a similar situation, but then you could only select one sheet at a time (by using a combobox).
But this means that the user had to click the submit button for each sheet he wants to copy the data.
If the user could select all sheets in one time and click one time the "submit" it would be "userfriendly".

image_checkbox.png


Following choices are possible

1. For each checkbox selected the data in the textboxes should be copied to the sheet which has the same name as the selected boxes.
So the user can select multiple boxes to copy the data to multiple sheets in one time
2. If checkbox B and C is selected, the data should be copied to both sheets and also be copied to sheet "BC"
3. If checkbox A and B and C is selected, the data should be copied to all three sheets and also be copied to sheet "ABC"
image_checkbox_sheets.png


Many thanks for your advice
grtz
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Put the following in your userform code:

VBA Code:
Private Sub CommandButton1_Click()
  'Validations
  If TextBox1.Value = "" Then
    MsgBox "Enter ID"
    Exit Sub
  End If
  If TextBox2.Value = "" Then
    MsgBox "Enter Name"
    Exit Sub
  End If
  If TextBox3.Value = "" Then
    MsgBox "Enter Firt Name"
    Exit Sub
  End If
  
  If CheckBox1.Value + CheckBox2.Value + CheckBox3.Value = 0 Then
    MsgBox "Mark checkbox"
    Exit Sub
  End If
  
  'Add data
  If CheckBox1.Value = True Then Call Add_Data(CheckBox1.Caption)
  If CheckBox2.Value = True Then Call Add_Data(CheckBox2.Caption)
  If CheckBox3.Value = True Then Call Add_Data(CheckBox3.Caption)
End Sub

Private Sub Add_Data(sName As String)
  Dim lr As Long
  If Evaluate("ISREF('" & sName & "'!A1)") Then
    With Sheets(sName)
      lr = .Range("B" & Rows.Count).End(3).Row + 1
      .Range("A" & lr).Value = TextBox1.Value
      .Range("B" & lr).Value = TextBox4.Value
      .Range("C" & lr).Value = TextBox2.Value & " " & TextBox3.Value
      .Range("D" & lr).Value = TextBox5.Value
    End With
  End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,155
Messages
6,170,405
Members
452,325
Latest member
BlahQz

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