This is commandbutton 1 click updated.
Private Sub CommandButton1_Click()
'Fill In Columns for CSV
Dim intStoreNumberRow As Integer
Dim intQuantityRow As Integer
Dim intStoreNumberColumn As Integer
Dim intQuantityColumn As Integer
Dim intSheet4Row As Integer
Dim intSheet4Counter As Integer
Dim last_Row As Integer
Dim x As Integer
'last_Row = Range(Cells(1, intStoreNumberColumn), Cells(40, intStoreNumberColumn)).End(xlUp).Row
'First Row that Data Should Appear
intSheet4Row = 2
intSheet4Counter = 1
'Store Numbers are stored in F1:GR40
For intStoreNumberColumn = 6 To 200
last_Row = Range(Cells(1, intStoreNumberColumn), Cells(40, intStoreNumberColumn)).End(xlUp).Row
For x = 1 To last_Row
'Quantities are stored in F43:GR500
For intQuantityRow = 43 To 47
'If there is a Store Number and Quantity, then proceeds to fill
If Sheet3.Cells(x, intStoreNumberColumn) <> "" And Sheet3.Cells(intQuantityRow, intStoreNumberColumn) <> 0 Then
'Increases Counter by 1
intSheet4Counter = intSheet4Counter + 1
'Randa Company - stays same
Sheet4.Cells(intSheet4Counter, 1) = Sheet3.Cells(1, 2)
'Randa Division - stays same
Sheet4.Cells(intSheet4Counter, 2) = Sheet3.Cells(2, 2)
'Corporation - stays same
Sheet4.Cells(intSheet4Counter, 3) = Sheet3.Cells(4, 2)
'Sold To/Company - stays same
Sheet4.Cells(intSheet4Counter, 4) = Sheet3.Cells(5, 2)
'Store Number - changes
Sheet4.Cells(intSheet4Counter, 5) = Sheet3.Cells(x, intStoreNumberColumn)
'UPC Code - changes
Sheet4.Cells(intSheet4Counter, 6) = Sheet3.Cells(intQuantityRow, 5)
'Order Type - stays same
Sheet4.Cells(intSheet4Counter, 7) = "RPL"
'Promotion Code - stays same
Sheet4.Cells(intSheet4Counter, 8) = "..."
'PO Number - stays same
Sheet4.Cells(intSheet4Counter, 9) = Sheet3.Cells(8, 2)
'Wholesale Price - stays same
Sheet4.Cells(intSheet4Counter, 10) = Sheet3.Cells(11, 2)
'Retail Price - stays same
Sheet4.Cells(intSheet4Counter, 11) = Sheet3.Cells(13, 2)
'Start Date - stays same
Sheet4.Cells(intSheet4Counter, 12) = Sheet3.Cells(9, 2)
'Cancel Date - stays same
Sheet4.Cells(intSheet4Counter, 13) = Sheet3.Cells(10, 2)
'Department Number -stays same
Sheet4.Cells(intSheet4Counter, 14) = Sheet3.Cells(7, 2)
'Replenishment Order Units - changes
Sheet4.Cells(intSheet4Counter, 15) = Sheet3.Cells(intQuantityRow, intStoreNumberColumn)
End If
Next intQuantityRow
Next x
Next intStoreNumberColumn
'Format Info
Columns("A:A").Select
Selection.NumberFormat = "00"
Columns("B:B").Select
Selection.NumberFormat = "00"
Columns("C:D").Select
Selection.NumberFormat = "General"
Columns("E:E").Select
Selection.NumberFormat = "0000"
Columns("F:F").Select
Selection.NumberFormat = "000000000000"
Columns("G:H").Select
Selection.NumberFormat = "General"
Columns("J:K").Select
Selection.NumberFormat = "0.00"
Columns("L:M").Select
Selection.NumberFormat = "mm/dd/yyyy"
Columns("N:N").Select
Selection.NumberFormat = "000"
Columns("O:O").Select
Selection.NumberFormat = "00000000000"
End Sub
This is based on the what "I think" you are trying to do. First of all I don't loop from 1 to 40. I loop until the first blank appears. So that cuts down some time. Secondly, your very inner loop doesn't make sense.
You loop from 43-340 but the values you copy are within rows 43-47.
*** the values you are testing are within rows 43-47.
Anyways, replace the above code and tell me what happens or if I misunderstood what you are doing.
Thanks!
edit: In hindsight maybe it is 43-340 because you have more rows in the real version.
Bookmarks