Move row from one sheet to another (on checkbox click)

Jakezer

New Member
Joined
Mar 24, 2022
Messages
19
Office Version
  1. 2019
Platform
  1. Windows
Hello,
I have this code to cut a row from one sheet to another, if the checkbox exists in front of that row,
I want to make it work if the checkbox exists and is checked if possible
Something like
VBA Code:
If ChkBx.Value = 1 & CB.Value = xlOn Then
The problem is that when i click on a checkbox using the other code, it's cutting all rows that has checkboxes infront of them starting from one i checked till the last row containing checkbox
Code:
Sub CopyRows()

    Dim ws1 As Worksheet
    Set ws1 = Worksheets("Sheet1")

    Dim ws2 As Worksheet
    Set ws2 = Worksheets("Sheet2")

    Dim LRow As Long
    LRow = ws2.Range("A" & Rows.Count).End(xlUp).Row

    Dim r As Long

    Dim ChkBx As CheckBox
    For Each ChkBx In ws1.checkboxes
        If ChkBx.Value = 1 Then

            LRow = LRow + 1
            r = ChkBx.TopLeftCell.Row

            ws2.Range("A" & LRow & ":E" & LRow).Value = _
            ws1.Range("A" & r & ":E" & r).Value

        End If
    Next

End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Forum statistics

Threads
1,213,567
Messages
6,114,344
Members
448,570
Latest member
rik81h

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