Copy, paste special, all checked rows in range

pann8888

New Member
Joined
Mar 16, 2012
Messages
13
I have a sheet (Data_View) with 300 rows of information. In column A, there is a checkbox for each row (checked box = TRUE). If a given row’s checkbox is clicked, I need that row’s information to be copied and pasted (values only) to a separate worksheet (Selected_Items). I can write code to do this for a specific row, but I don’t know how to write a loop that will check all 300 rows for the condition, copy only the checked rows, then paste the copied data into successive rows in Selected_Items sheet.

I’ve attempted to modify code from other posts related to this topic, but I'm a VBA novice and I haven’t gotten it right yet. My efforts thus far are available for advice (and mockery) below. Any help would be greatly appreciated.

Code:
Dim rng As Range
Dim row As Range
Dim cell As Range
Dim nextrow as Long
Nextrow = Sheets.(“Selected_Items”).cells(Rows.Count, “A”).End(xlUp).Row +1
Set rng = Range("A2:BD2")
Sheets(“Data_View”).Select
 For Each row In rng.Rows
   For Each cell in row.Cells
If Range(“A”).value = True then row.copy
Sheets("Selected_Items").Cells(nextrow, “A”).PasteSpecial Paste:=xlValues
Next cell
Next row
End if
End sub


</PRE>
 
Last edited:

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
What kind of check box do you have? Is it from the Formas toolbar or ActiveX from the Controls Toolbox? When you say they are in column A, are they wholly contained by the Row in which they sit (ie so the checkbox for A2 would not cross the top or bottom cell boundary of A2)?
 
Upvote 0
Exactly- each checkbox is wholly contained by the row in which it sits. If a box is checked, it returns "TRUE" in its cell (e.g., A2). I used the following code to add the checkboxes.

Code:
</SPAN></SPAN>Sub AddCheckBoxes()
On Error Resume Next
Dim c As Range, myRange As Range
Set myRange = Selection
For Each c In myRange.Cells
ActiveSheet.CheckBoxes.Add(c.Center, c.Center, c.Width, c.Height).Select
With Selection
.LinkedCell = c.Address
.Characters.Text = ""
.Name = c.Address
End With
c.Select
With Selection
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, _
Formula1:="=" & c.Address & "=TRUE"
.FormatConditions(1).Font.ColorIndex = 6
.FormatConditions(1).Interior.ColorIndex = 6
.Font.ColorIndex = 2
End With
Next
myRange.Select
End Sub
</SPAN>
 
Upvote 0
Ah I see - well, you've got most of the problems sorted by making it place True in the cells. Try this:

Code:
Sub Copy_Data()
Dim cell As Range

With Sheets("Data_View")   'amend as required
  For Each cell In .Range("A2:A" & .Cells(.Rows.Count,"A").End(xlUp).Row)
    If Typename(cell.Value) = "Boolean" Then
          If cell.Value = True Then 
                With Sheets("Selected_Items")
                    cell.EntireRow.Copy
                    .Cells(.Rows.Count,"A").End(xlUp).Offset(1).PasteSpecial xlPasteValues
                End With
          End if
       End If
   Next cell
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,226,065
Messages
6,188,678
Members
453,490
Latest member
amru

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