Copy rows to another sheet based on checkbox and cell value

belle_the_cat

New Member
Joined
Jun 23, 2021
Messages
7
Office Version
  1. 365
  2. 2013
Platform
  1. Windows
  2. MacOS
Hi folks!

I have a sheet with a bunch of data on it, which spans A:K. The number of rows is variable. I have a userform with three checkboxes on it:
[] Cats
[] Dogs
[] Goldfish

The checkboxes correspond to possible values in column K. If a checkbox is ticked, I want rows where K = a ticked value to be copied to another sheet. (So like if cats and goldfish are ticked, the rows that have "cats" or "goldfish" would be copied over to the other sheet.)

I am an idiot and have no idea how to accomplish this. Any help or advice on how to get started would be much appreciated!
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Specific details are important:
You said:
I have a sheet with a bunch of data on it, which spans A:K.
But did not say what the name of the sheet was:

And then you said:
I want rows where K = a ticked value to be copied to another sheet.
What is the name of the sheet.

Saying another sheet is not specific.
 
Upvote 0
Specific details are important:
You said:
I have a sheet with a bunch of data on it, which spans A:K.
But did not say what the name of the sheet was:

And then you said:
I want rows where K = a ticked value to be copied to another sheet.
What is the name of the sheet.

Saying another sheet is not specific.
They are Sheet1 and Sheet2, respectively.

Edit: I’m sorry for the (very) delayed reply!
 
Last edited:
Upvote 0
They are Sheet1 and Sheet2, respectively.

Edit: I’m sorry for the (very) delayed reply!
So no matter what checkbox you clicked it always looks in sheet1 column K for the value and copies this row to Sheet2. Is that correct?
 
Upvote 0
I think I phrased it poorly initially, so let me take another crack at explaining it, and let me know if this makes any sense.

Sheet1 has a bunch of data, and it spans columns A:K. The K column contains types of animals.

I have a userform with three tick boxes:
[] Cats
[] Dogs
[] Goldfish

When someone clicks the command button in the userform, presumably after checking one or more of the tickboxes, I want it to do this –
(this is the plain English version of what I'm trying to accomplish)

VBA Code:
For each row in the range of Sheet1 A1:A to last row
Look at the row and

If cats_tickbox is true and the value of K = "cats"
    then copy A:J of that row over to sheet2
        and then go to the next row and continue until it looks at every row
        
If dogs_tickbox is true and the value of K = "dogs"
    then copy A:J of that row over to sheet2
        and then go to the next row and continue until it looks at every row
        
If goldfish_tickbox is true and the value of K = "goldfish"
    then copy A:J of that row over to sheet2
        and then go to the next row and continue until it looks at every row

Does that clarify it at all?
 
Upvote 0
You can try this but I'm using a Windows Platform
Your using a Mac so not sure if this will work on a Mac
Put this script in a button on your UserForm
VBA Code:
Private Sub CommandButton1_Click()
'Modified  5/3/2022  3:02:33 AM  EDT
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Dim Lastrowb As Long
Dim b As Long
Dim ctrl As MSForms.Control
 
For Each ctrl In Me.Controls
    Select Case True
        Case TypeOf ctrl Is MSForms.CheckBox
            If ctrl.Value = True Then
                Lastrow = Sheet1.Cells(Rows.Count, "A").End(xlUp).Row
                Lastrowb = Sheet2.Cells(Rows.Count, "A").End(xlUp).Row
    
                For b = 1 To Lastrow
                    If Sheet1.Cells(b, "K").Value = ctrl.Name Then
                        Lastrowb = Lastrowb + 1
                        Sheet1.Cells(b, 1).Resize(, 10).Copy Sheet2.Cells(Lastrowb, 1)
                     End If
                Next

            End If
        End Select
Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,046
Messages
6,122,854
Members
449,096
Latest member
Erald

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