Copy values of previus cell, if the value is not zero

ppvivanco

New Member
Joined
Sep 4, 2014
Messages
5
Hi,

I need to do the following macro:

I have one shipment report, where I put the quantity (in Metric tons) that I sent to each place. One place is our warehouse, and I need, if the lot appear like delivered, one macro to show the number of lots delivered in other range.

The table is the following:

Whs
LotAllocatedInBalance
XXY 010120 -20
XXY 0102
XXY 0103
XXY 010420 -20
XXY 010520 -20
XXY 0106
XXY 0107
XXY 0108
XXY 0109
XXY 0110
XXY 0111
XXY 0112
XXY 0113
XXY 01142020D
XXY 01152020D
XXY 0116
XXY 0117
XXY 0118
XXY 01192020D
XXY 01202020D
XXY 0121

<colgroup><col><col span="2"><col></colgroup><tbody>
</tbody>
And I need, if the Balance show "D", the values (XXY 0120 in example) copied in other place. If this possible?

Thanks
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Code:
Sub moveThings()

    For x = 2 To ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
        If Cells(x, 4).Value = "D" Then
            Cells(x, 1).Copy Destination:= 'somewhere
        End If
    Next x
End Sub
 
Upvote 0
Code:
Sub moveThings()

    For x = 2 To ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
        If Cells(x, 4).Value = "D" Then
            Cells(x, 1).Copy Destination:= 'somewhere
        End If
    Next x
End Sub

Hi, Thanks for your answer.

I put the results in A30 (Cells(x, 1).Copy Destination:=Range("A30")), but only show one result, and not all. Any idea?


Thanks in advance,
 
Last edited:
Upvote 0
Code:
Sub moveThings()

    Dim nextRow As Long


    nextRow = 56


    For x = 2 To ActiveSheet.Cells(Rows.Count, "D").End(xlUp).Row
        If Cells(x, 4).Value = "D" Then
            Cells(x, 1).Copy Destination:=Cells(nextRow, 1)
            nextRow = nextRow + 1
        End If
    Next x
End Sub

I moved the criteria to count cells to column D because adding below A would increase with each run time. Very small change.
 
Upvote 0
Code:
Sub moveThings()

    Dim nextRow As Long


    nextRow = 56


    For x = 2 To ActiveSheet.Cells(Rows.Count, "D").End(xlUp).Row
        If Cells(x, 4).Value = "D" Then
            Cells(x, 1).Copy Destination:=Cells(nextRow, 1)
            nextRow = nextRow + 1
        End If
    Next x
End Sub

I moved the criteria to count cells to column D because adding below A would increase with each run time. Very small change.

Yes, it is working correctly.

Thanks!!
 
Upvote 0
Last thing,

How I can to do for paste the values in the first empty cell from A56? For example, I configure the Macro to paste from A56, but manually I wrote in A56, A57, A58, etc. How I can configure the Macro for paste in first blank cell?

Regards,
 
Upvote 0

Forum statistics

Threads
1,214,551
Messages
6,120,156
Members
448,948
Latest member
spamiki

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