Is there a way to move cells from sheet 1 to sheet 2 based on if their checkbox is checked or not?
Ideally, I want it to work both ways, if the box is checked it moves to the other sheet, but if it becomes unchecked, it is deleted from sheet 2. I have about 800 accounts that I need to send to a customer for verification.
The code I have now successfully copies the row to sheet 2 but there are two problems:
1. The box has to be go from unchecked to checked to populate sheet 2 (also will add an account more than once)
2. and if I uncheck the box (prom previously being checked) it doesn't remove the line from sheet 2.
I posted the code below but if its easier to post a new code entirely, that works also!
Thank you so much!
*****FOR SHEET ONE
Private Sub CheckBox1_Click()
MoveCheckBoxData CheckBox1
End Sub
Private Sub CheckBox2_Click()
MoveCheckBoxData CheckBox2
End Sub
Private Sub CheckBox3_Click()
MoveCheckBoxData CheckBox3
End Sub
Private Sub CheckBox4_Click()
MoveCheckBoxData CheckBox4
End Sub
***** goes on to checkbox800
Sub MoveCheckBoxData(cObject As Object)
Dim xlInt, xlColumn, i As Integer
Dim xlRow As Long
Dim xlStr As String
Dim xlRng As Range
Dim xlSht, xlSht2 As Worksheet
'Get row that Checkbox is in
xlInt = cObject.TopLeftCell.Row
xlStr = "C" & CStr(xlInt)
'If Check box is true then add data to sheet2
If cObject.Value = True Then
Set xlSht2 = Sheet2
xlRow = xlSht2.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
xlColumn = xlSht2.Cells(xlRow, Columns.Count).Column
For i = 1 To xlColumn
Select Case xlSht2.Cells(xlRow, i)
Case Is <> vbNullString
xlRow = xlSht2.Cells(Rows.Count, i).End(xlUp).Offset(1, 0).Row
Exit For
Case Else
'do nothing everything ok
End Select
Next i
Set xlSht = Sheet1
Set xlRng = xlSht.Range("C" & xlInt, "AB" & xlInt)
xlRng.Copy Destination:=xlSht2.Cells(xlRow, 1)
Application.CutCopyMode = False
Else
'Future code to only insert unique records?
End If
Set xlSht = Nothing: Set xlSht2 = Nothing: Set xlRng = Nothing
End Sub
Bookmarks