Help with checkbox macros

itsMelly

New Member
Joined
Jun 20, 2024
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hi, I am trying to have all information in a given row (from columns A:F) automatically copied over to a separate worksheet if the checkbox is clicked.

I have tried scouring the internet for about 3 hours with no luck, so now I’m here. Can anyone help out with this?

I have attached a screenshot, as well as a OneDrive link to a copy of the sheet if you’d prefer to work in there. Thanks in advance : )

Plz Help Me Reddit.xlsx
 

Attachments

  • IMG_0399.png
    IMG_0399.png
    133 KB · Views: 22

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Hello @itsMelly. You are using Search poorly... Look at this topic "Checkbox - True - Moves Whole Row To Another Sheet" similar to your question. I think you can adapt the code to your needs. Good luck.
Thanks for the reply. I went back and looked over the thread, but it looks like the example files are restricted, I cannot view them. And I’m pretty new to this, so it’s not the most intuitive to just look at code meant for someone else’s sheet and then fix it to work on mine, I’m sorry.
 
Upvote 0
Firstly, you need to assign a macro to run to the .OnAction property of each check box.
Then you need that assigned macro to deal with the check box just clicked.

Copy this into a standard module.
VBA Code:
Option Explicit

Sub ApplyOnAction()
    Dim rng As Range
    Dim cbx As CheckBox
    
Set rng = Sheets("Sheet1").Range("A3:A17")

For Each cbx In ActiveSheet.CheckBoxes
    If Not Intersect(cbx.TopLeftCell, rng) Is Nothing Then
        cbx.OnAction = "CopyTheRange"      'runs each time clicked
    End If
Next cbx

End Sub


Sub CopyTheRange()
    
    Dim whoCalled As String, copyRng As Range
    Dim lr As Long
    
    whoCalled = Application.Caller
    
    If ActiveSheet.CheckBoxes(whoCalled).Value = xlOn Then
        Set copyRng = Range(ActiveSheet.CheckBoxes(whoCalled).TopLeftCell.Address(0, 0)).Resize(, 6)
        With Sheets("Sheet2")
            lr = .Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
            .Range("A" & lr + 1).Resize(, 6).Value = copyRng.Value
        End With
    End If

End Sub
Run the ApplyOnAction sub once to assign the CopyTheRange macro to the OnAction property of the check boxes.
Now, clicking a check box runs the CopyTheRange macro.

Hope this is of some use.
 
Upvote 0
Firstly, you need to assign a macro to run to the .OnAction property of each check box.
Then you need that assigned macro to deal with the check box just clicked.

Copy this into a standard module.
VBA Code:
Option Explicit

Sub ApplyOnAction()
    Dim rng As Range
    Dim cbx As CheckBox
   
Set rng = Sheets("Sheet1").Range("A3:A17")

For Each cbx In ActiveSheet.CheckBoxes
    If Not Intersect(cbx.TopLeftCell, rng) Is Nothing Then
        cbx.OnAction = "CopyTheRange"      'runs each time clicked
    End If
Next cbx

End Sub


Sub CopyTheRange()
   
    Dim whoCalled As String, copyRng As Range
    Dim lr As Long
   
    whoCalled = Application.Caller
   
    If ActiveSheet.CheckBoxes(whoCalled).Value = xlOn Then
        Set copyRng = Range(ActiveSheet.CheckBoxes(whoCalled).TopLeftCell.Address(0, 0)).Resize(, 6)
        With Sheets("Sheet2")
            lr = .Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
            .Range("A" & lr + 1).Resize(, 6).Value = copyRng.Value
        End With
    End If

End Sub
Run the ApplyOnAction sub once to assign the CopyTheRange macro to the OnAction property of the check boxes.
Now, clicking a check box runs the CopyTheRange macro.

Hope this is of some use.
Will try this today, thank you!
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,181
Members
452,615
Latest member
bogeys2birdies

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