Copy data to another sheet if it meets criteria

joand

Active Member
Joined
Sep 18, 2003
Messages
267
I have two columns (C and D) in Sheet1.

I need to copy the range in Column D (Range D10:D29) to another worksheet (Sheet2) if the value in Column C (Range C10:C29) exceeds 0.

For example, if the value of C10 is 1, then the data in D10 is copied to Sheet2 (probably in A1 perhaps), then checks the value of the next row C11, if it is greater than 0, then the data in D11 is copied to Sheet2 A2.

However, if C12 is 0, then then the data in D12 is NOT COPIED. If the next row C13 is greater than 0 then the data in D13 is copied to Sheet2 A3, and so on.

Can you help me get started?
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Try

Code:
Sub cpy()
Dim LR As Long, i As Long
With Sheets("Sheet1")
LR = .Range("C" & Rows.Count).End(xlUp).Row
    For i = 1 To LR
        With .Range("C" & i)
            If .Value > 0 Then .Offset(, 1).Copy Destination:=Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1)
        End With
    Next i
End With
End Sub
 
Upvote 0
Hi,

Try something like this:

Code:
Sub test()
    Dim lRow, i As Integer
    lRow = Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row
    For i = 10 To 29
        If Cells(i, 3).Value > 0 Then
            Cells(i, 4).Copy Destination:=Sheets("Sheet2").Range("A" & lRow)
            lRow = lRow + 1
        End If
    Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,789
Members
452,942
Latest member
VijayNewtoExcel

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