+ Reply to Thread
Results 1 to 7 of 7

Copy rows if checkboxes are checked

  1. #1
    Registered User
    Join Date
    09-19-2014
    Location
    Philadelphia,PA
    MS-Off Ver
    2010
    Posts
    54

    Copy rows if checkboxes are checked

    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

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Copy rows if checkboxes are checked

    please post a workbook.

    It is so much easier

  3. #3
    Registered User
    Join Date
    09-19-2014
    Location
    Philadelphia,PA
    MS-Off Ver
    2010
    Posts
    54

    Re: Copy rows if checkboxes are checked

    SAMPLE.xls

    Sorry about that! Here is a sample!

  4. #4
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Copy rows if checkboxes are checked

    Ok

    I can move each row to sheet 2 if the check box is ticked.

    This will work for each row in turn.

    Now if the box is un ticked are you saying you want it moved back to sheet 1?

  5. #5
    Registered User
    Join Date
    09-19-2014
    Location
    Philadelphia,PA
    MS-Off Ver
    2010
    Posts
    54

    Re: Copy rows if checkboxes are checked

    If the box in sheet 1 is ticked, I want a copy of it to go to sheet 2
    Then, if you un check the box in sheet 1, I want the information that was copied into sheet 2 to be deleted from sheet 2

    So only the checked boxes will appear in sheet 2
    And sheet 1 will show all the checked AND non-checked boxes

  6. #6
    Registered User
    Join Date
    09-19-2014
    Location
    Philadelphia,PA
    MS-Off Ver
    2010
    Posts
    54

    Re: Copy rows if checkboxes are checked

    Sorry if I am not explaining this well!

  7. #7
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Copy rows if checkboxes are checked

    My Apologies regarding the delay. PC Crashed

    I created a few Macros for you.

    These are triggerred by the checkbox event:
    MoveRow
    DeleteRow

    MacroCreate is run by the button on sheet "MacroCreate"

    enter the number of checkboxes in cell c1 and click on the button

    The macro will create the Checkbox_Click event for all your checkboxes and select them.

    Copy the selected range and paste into the sheet specific vba module.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Summing checked checkboxes
    By bermudamohawk in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-13-2014, 11:25 AM
  2. Replies: 4
    Last Post: 12-30-2013, 10:10 AM
  3. How to copy only checked checkboxes into new cell?
    By GTX2013 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-06-2013, 09:06 PM
  4. How to run a macro if checkboxes are checked in a range
    By franksonata in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-07-2012, 07:31 AM
  5. [SOLVED] My checkboxes will not stay checked.
    By NUMBnut in forum Excel General
    Replies: 0
    Last Post: 01-09-2006, 05:10 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1