+ Reply to Thread
Results 1 to 2 of 2

VBA Copy row into new worksheet based on Control Form Check Box

Hybrid View

carlosriver24 VBA Copy row into new... 03-06-2013, 10:27 PM
carlosriver24 Re: VBA Copy row into new... 03-06-2013, 10:42 PM
  1. #1
    Registered User
    Join Date
    07-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    33

    VBA Copy row into new worksheet based on Control Form Check Box

    Hello,

    I am hoping someone might be able to help me with this issue. I have over 3,000 rows in a worksheet with data in each column from A8 to D3000. In column E, I have inserted a form control check box.

    I need a macro that will find which rows are selected by the check box (keep in mind I have hidden rows with check boxes that may or may not be selected), and copy those selected rows to another worksheet named "Products Summary" and paste them in that tab beginning at A8.

    Here is a similar code that I am using with a dropdown:

    Sub copy()
    
    Sheets("Product Data").Select
    
        Dim tfCol As Range, cell As Object
         
        Set tfCol = Range("E8:E65536")
         
        For Each cell In tfCol
            If (cell.EntireRow.Hidden = True) Then
                wasHidden = 1
                cell.EntireRow.Hidden = False
            End If
            
            If IsEmpty(cell) Then
                'Move to the next one
            End If
             
            If cell.Value = "Yes" Then
                cell.EntireRow.Copy
                Sheets("Products Summary").Select
                ActiveSheet.Range("A65536").End(xlUp).Select
                Selection.Offset(1, 0).Select
                ActiveSheet.Paste
            End If
            
            If (wasHidden = 1) Then
               cell.EntireRow.Hidden = True
               wasHidden = 0
            End If
             
        Next
    
    End Sub
    Any help is much appreciated.

    Kind regards!

  2. #2
    Registered User
    Join Date
    07-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    33

    Re: VBA Copy row into new worksheet based on Control Form Check Box

    I found this code, but it does not work for me. Any advice?

    Sub CopyRows()
    
    For Each chkbx In ActiveSheet.CheckBoxes
        If chkbx.Value = 1 Then
            For r = 1 To Rows.Count
                If Cells(r, 1).Top = chkbx.Top Then
                    With Worksheets("Products Summary")
                        LRow = .Range("A" & Rows.Count).End(xlUp).Row + 1
                        .Range("A" & LRow & ":E" & LRow) = _
                        Worksheets("Product Data").Range("A" & r & ":E" & r).Value
                    End With
                    Exit For
                End If
            Next r
        End If
    Next
    
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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