Check box with 2 conditons

kiwikiki718

Board Regular
Joined
Apr 7, 2017
Messages
80
Office Version
  1. 365
Platform
  1. Windows
Hello I am having a issue trying to create a formula that when a checkbox is checked to copy the data from worksheet 1 to specific cells in worksheet 2. If the cell that is being copied over is blank then it should display blank on worksheet 2. If the checkbox is unchecked C5:C12,B5:B12,D6:D12 should display blank. With people having the ability to manually update the cells if needed.

Example: work sheet 1 C5:C12,B5:B12,D6:D12 has the referenced data that I want to copy to worksheet 2 C5:C12,B5:B12,D6:D12 when checkbox(C3) is checked.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
You'll need to have some VBA code that is run when user changes the status of (clicks on) the checkbox. Generally it is preferable to use a "form" type checkbox (requires access to Developer menu item in a .xlsm -- or macro enabled -- file). Then "Assign Macro" to the check box (right click on the check box). Ideally you name the checkbox too. I named the example "MyCheckBox." Do that using the data field under ribbon on the left of the Excel screen (above cell A1).

'This MIGHT be what you need...

'1 C5:C12,B5:B12,D6:D12 in sheet 1 has the referenced data and checkbox
'2 C5:C12, B5:B12,D6:D12 in sheet 2 are copy to (target) cells.

VBA Code:
Sub CheckboxClickThenCopy()

    If Worksheets("Sheet1").CheckBoxes("MyCheckBox").Value = Checked Then
            
        With Worksheets("Sheet1")
    
            .Range("B5:B12").Copy
            Worksheets("Sheet2").Range("B5:B12").PasteSpecial Paste:=xlPasteValues
        
            .Range("C5:C12").Copy
            Worksheets("Sheet2").Range("C5:C12").PasteSpecial Paste:=xlPasteValues
            
            .Range("D6:D12").Copy
            Worksheets("Sheet2").Range("D6:D12").PasteSpecial Paste:=xlPasteValues
            
'           Turn off copy.
            Application.CutCopyMode = False
                    
'           Need to activate one cell in the target worksheet.
            Worksheets("Sheet2").Activate
            Range("D5").Activate
            
            .Activate  'Sheet 1
        
        End With
        
    Else
        Worksheets("Sheet2").Range("B5:B12,C5:C12,D6:D12").Value = ""
    End If

End Sub
 

Attachments

  • CheckboxCopyCells.png
    CheckboxCopyCells.png
    13.6 KB · Views: 10
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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