Checkbox to ActiveX checkbox change in VBA

esitze

New Member
Joined
Aug 24, 2018
Messages
18
Can anyone tell me if the below code is able to be run with ActiveX checkboxes? Any help is greatly appreciated!!!

Sub CopyRowsPipefitters()

Dim LRow As Long, ChkBx As CheckBox, WS2 As Worksheet
Set WS2 = Worksheets("Dispatch")
Set WS4 = Worksheets("Pipefitters")
ThisWorkbook.Unprotect Password:="a"
WS2.Unprotect Password:="a"
WS2.Visible = True
Range("A9:R300").ClearContents
Range("B2").Select
LRow = WS2.Range("A" & Rows.Count).End(xlUp).Row
WS4.Select
For Each ChkBx In ActiveSheet.CheckBoxes
If ChkBx.Value = 1 Then
LRow = LRow + 1
WS2.Cells(LRow, "A").Resize(, 9) = Range("F" & ChkBx.TopLeftCell.Row).Resize(, 9).Value
End If
Next
WS4.Visible = False
WS2.Protect Password:="a"
ThisWorkbook.Protect Password:="a"
Call WS2.Activate
End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
First declare the following...

VBA Code:
    Dim OleObj As OLEObject

Then try replacing your For Each/Next loop with the following...

VBA Code:
    For Each OleObj In ActiveSheet.OLEObjects
        If TypeName(OleObj.Object) = "CheckBox" Then
            If OleObj.Object.Value = True Then
                LRow = LRow + 1
                WS2.Cells(LRow, "A").Resize(, 9) = Range("F" & OleObj.TopLeftCell.Row).Resize(, 9).Value
            End If
        End If
    Next OleObj

Hope this helps!
 
Upvote 1
Solution

Forum statistics

Threads
1,224,815
Messages
6,181,136
Members
453,021
Latest member
Justyna P

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