Selective copying macro

jon321

New Member
Joined
Oct 27, 2008
Messages
47
Hey Im completely stuck, I need to do the following,

If any cell in a range contains the word "TRUE" then the macro copies 4 cells in that row and paste special "values" on sheet 2 starting at A1 and then moving to A2 if there is something already in A1.

Hope someone can help!!
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
the range is "b2:E10" and the 4 cells on the row within the range eg.

B2,C2,D2,E2 If true was found on this row.
 
Upvote 0
Try

Code:
Sub cpy()
Dim i As Integer
With Sheets("Sheet1")
    For i = 2 To 10
        If WorksheetFunction.CountIf(.Range("B" & i).Resize(, 4), True) > 0 Then
            .Range("B" & i).Resize(, 4).Copy Destination:=Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1)
        End If
    Next i
End With
End Sub
 
Upvote 0
Works to some extent - but it doesnt do "paste special -values" and starts in cell a2 on sheet 2???
 
Upvote 0
Code:
Sub cpy()
Dim i As Integer
With Sheets("Sheet1")
    For i = 2 To 10
        If WorksheetFunction.CountIf(.Range("B" & i).Resize(, 4), True) > 0 Then
            .Range("B" & i).Resize(, 4).Copy
            Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
        End If
    Next i
End With
On Error Resume Next
With Sheets("Sheets2").Columns("A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
On Error GoTo 0
End Sub

Take it or leave it.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,927
Messages
6,122,309
Members
449,080
Latest member
jmsotelo

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