If value = 0 then do not add iRow to table?

whahmira

New Member
Joined
Aug 23, 2018
Messages
9
Hello! I have a "Ship" button with a macro that copies filled out rows in an order form and adds them to a list of shipments in another workbook.
In Workbook A, there is a table of part numbers and their quantities, referred to in the code as iRow. Sometimes I have to make partial shipments, so I will fill out the order form to have a quantity of "0" on the part numbers that will not be shipped in that particular order.
I would like to create a macro that senses if there is a quantity of 0, that specific iRow does not get transferred to the shipments list.
The shipments list is referred to as kRow in the macro. Below you can see the code.

Code:
[COLOR=#008000]'This section copies the necessary information from Order Overview to Shipments List[/COLOR]
Sheets("Order Form").Activate
OrderNo = Range("B2").Value
Dim PartNo(100) As String
Dim Quantity(100) As Integer
Dim iRow As Integer
   iRow = 8 [COLOR=#008000]'start one row early or it will skip the first row of the order[/COLOR]
   Do Until IsEmpty(Cells(iRow, 1))
   iRow = iRow + 1
   PartNo(iRow) = Cells(iRow, 1).Value
   Quantity(iRow) = Cells(iRow, 5).Value
   Loop
maxRow = iRow
iRow = 9 [COLOR=#008000]'added this line to stop error of adding extra empty row[/COLOR]
[COLOR=#008000]'opens up the ship list[/COLOR]
Workbooks.Open Filename:= _
        "C:\Users\Z645352\Desktop\Test1\WorkbookB.xlsm"
[COLOR=#008000]
'naming a kRow [/COLOR]
   With Sheets("Shipments")
        kRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1 [COLOR=#008000]'finds first empty row so that the code will not continue to rewrite in the same row over and over again[/COLOR]
    End With
    Do Until iRow = maxRow
[COLOR=#ff0000]'-------I was thinking to insert the If statement here, but didn't really know how to do it for iRows and kRows-------------[/COLOR]
Cells(kRow, 1).Value = PartNo(iRow)

Cells(kRow, 4).Value = Quantity(iRow)
Cells(kRow, 3).Value = Filenm
Cells(kRow, 2).Select 'add a hyperlink to the cell where the ShipNo appears
    ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="C:\Users\Z645352\Desktop\Test1\ShippingDoc\" & Filenm & "2018" & ShipNo & ".xlsm", TextToDisplay:=Filenm & "2018" & ShipNo
    
     iRow = iRow + 1
     kRow = kRow + 1
    Loop
    
ActiveWorkbook.Save
Application.CutCopyMode = False
Application.ScreenUpdating = True

End Sub
Any help would be greatly appreciated :)
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
@whahmira
Cross-Posting
While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0
This should do it:

Code:
    Do Until iRow = maxRow
[COLOR=#ff0000]if Quantity(iRow)>0 then[/COLOR]
Cells(kRow, 1).Value = PartNo(iRow)

Cells(kRow, 4).Value = Quantity(iRow)
Cells(kRow, 3).Value = Filenm
Cells(kRow, 2).Select 'add a hyperlink to the cell where the ShipNo appears
    ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="C:\Users\Z645352\Desktop\Test1\ShippingDoc\" & Filenm & "2018" & ShipNo & ".xlsm", TextToDisplay:=Filenm & "2018" & ShipNo
    
[COLOR=#ff0000]     kRow = kRow + 1
End If
     iRow = iRow + 1[/COLOR]


    Loop
 
Upvote 0
Sorry about the cross posting, I was going to post a link to the other post if it was answered correctly there, or vice versa.
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,198
Members
452,616
Latest member
intern444

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