I am in desperate need of some help, please!
I have an inventory sheet ("LOCATION") and an Order Form sheet ("Supply Usage Form").
I'm trying to get the below code to look at each row from row 9, column "B" to the last row (may vary from time to time) in the inventory sheet in columns 12 (missing items) and 13 (expired items) and if any numbers are found, copy certain cells from that same row over to the order form in certain cells. The bottom half of the code works perfectly every time. The problem comes in when I need to order more items than I have empty rows. The last empty row is row 53. The twist is that there is information below row 53 that needs to stay at the bottom of the form.
What WANT to happen is this... Until row 53 is filled, fill the order form from row 24 to 53 (this is the bottom half of the code below and it works beautifully). When row 53 is filled with data, I need a new row added below row 53 with the same format as row 53, and continue adding the data as before, all the while pushing the information at the bottom of the form down (inserting new rows after the last filled row and before the info at the bottom of the form).
What is ACTUALLY happening is... it adds the extra rows with the formatting just fine, but then it fills in column "B" of the order form with items listed from bottom to top (instead of top to bottom) AND the other columns are offset or simply blank... or it doesn't add any new rows and just fills in the next cells and overwrites the info at the bottom.
Any suggestions or help is GREATLY appreciated.
Sorry if this is confusing, but I'm confused on how to get it to do what I need it to do. I feel like I'm close, but I can't hammer it out. Please help!!!
Thank you in advance! If any more info is needed, please let me know.
I have an inventory sheet ("LOCATION") and an Order Form sheet ("Supply Usage Form").
I'm trying to get the below code to look at each row from row 9, column "B" to the last row (may vary from time to time) in the inventory sheet in columns 12 (missing items) and 13 (expired items) and if any numbers are found, copy certain cells from that same row over to the order form in certain cells. The bottom half of the code works perfectly every time. The problem comes in when I need to order more items than I have empty rows. The last empty row is row 53. The twist is that there is information below row 53 that needs to stay at the bottom of the form.
What WANT to happen is this... Until row 53 is filled, fill the order form from row 24 to 53 (this is the bottom half of the code below and it works beautifully). When row 53 is filled with data, I need a new row added below row 53 with the same format as row 53, and continue adding the data as before, all the while pushing the information at the bottom of the form down (inserting new rows after the last filled row and before the info at the bottom of the form).
What is ACTUALLY happening is... it adds the extra rows with the formatting just fine, but then it fills in column "B" of the order form with items listed from bottom to top (instead of top to bottom) AND the other columns are offset or simply blank... or it doesn't add any new rows and just fills in the next cells and overwrites the info at the bottom.
Any suggestions or help is GREATLY appreciated.
Sorry if this is confusing, but I'm confused on how to get it to do what I need it to do. I feel like I'm close, but I can't hammer it out. Please help!!!
Thank you in advance! If any more info is needed, please let me know.
Code:
Sub fillorder1()
Dim finalrow As Long
Dim i As Integer
Dim ExpDate As Date
Dim lastRow As Long
Application.ScreenUpdating = False
lastRow = Sheets("Supply Usage Form").Range("B22").End(xlDown).Row
finalrow = Sheets("Location").Range("B9").End(xlDown).Row
ExpDate = Date + 30
For i = 9 To finalrow
If (Sheets("Location").Cells(i, 12) <> "") And (Sheets("Location").Cells(i, 13) = "") And (lastRow >= 53) Then
Rows(lastRow + 1).Insert
Rows(lastRow).Copy
Rows(lastRow + 1).EntireRow.PasteSpecial Paste:=xlPasteFormats
Sheets("Location").Cells(i, 1).Copy
Cells(lastRow, "B").PasteSpecial xlPasteValuesAndNumberFormats
Sheets("Location").Cells(i, 2).Copy
Sheets("Supply Usage Form").Range("B22").End(xlDown).Offset(0, 1).PasteSpecial xlPasteValuesAndNumberFormats
Sheets("Location").Cells(i, 12).Copy
Sheets("Supply Usage Form").Range("B22").End(xlDown).Offset(0, 5).PasteSpecial xlPasteValuesAndNumberFormats
ElseIf (Sheets("Location").Cells(i, 12) = "") And (Sheets("Location").Cells(i, 13) <> "") And (lastRow >= 53) Then
Rows(lastRow + 1).Insert
Rows(lastRow).Copy
Rows(lastRow + 1).EntireRow.PasteSpecial Paste:=xlPasteForma
Sheets("Location").Cells(i, 1).Copy
Sheets("Supply Usage Form").Range("B22").End(xlDown).Offset(1, 0).PasteSpecial xlPasteValuesAndNumberFormats
Sheets("Location").Cells(i, 2).Copy
Sheets("Supply Usage Form").Range("B22").End(xlDown).Offset(0, 1).PasteSpecial xlPasteValuesAndNumberFormats
Sheets("Location").Cells(i, 13).Copy
Sheets("Supply Usage Form").Range("B22").End(xlDown).Offset(0, 6).PasteSpecial xlPasteValuesAndNumberFormats
ElseIf (Sheets("Location").Cells(i, 12) <> "") And (Sheets("Location").Cells(i, 13) <> "") And (lastRow >= 53) Then
Rows(lastRow + 1).Insert Rows(lastRow).Copy
Rows(lastRow + 1).EntireRow.PasteSpecial Paste:=xlPasteForma
Sheets("Location").Cells(i, 1).Copy
Sheets("Supply Usage Form").Range("B22").End(xlDown).Offset(1, 0).PasteSpecial xlPasteValuesAndNumberFormats
Sheets("Location").Cells(i, 2).Copy
Sheets("Supply Usage Form").Range("B22").End(xlDown).Offset(0, 2).PasteSpecial xlPasteValuesAndNumberFormats
Sheets("Location").Cells(i, 12).Copy
Sheets("Supply Usage Form").Range("B22").End(xlDown).Offset(0, 5).PasteSpecial xlPasteValuesAndNumberFormats
Sheets("Location").Cells(i, 13).Copy
Sheets("Supply Usage Form").Range("B22").End(xlDown).Offset(0, 6).PasteSpecial xlPasteValuesAndNumberFormats
ElseIf (Sheets("Location").Cells(i, 12) <> "") And (Sheets("Location").Cells(i, 13) = "") And (lastRow <> 53) Then
Sheets("Location").Cells(i, 1).Copy
Sheets("Supply Usage Form").Range("B22").End(xlDown).Offset(1, 0).PasteSpecial xlPasteValuesAndNumberFormats
Sheets("Location").Cells(i, 2).Copy
Sheets("Supply Usage Form").Range("B22").End(xlDown).Offset(0, 2).PasteSpecial xlPasteValuesAndNumberFormats
Sheets("Location").Cells(i, 12).Copy
Sheets("Supply Usage Form").Range("B22").End(xlDown).Offset(0, 5).PasteSpecial xlPasteValuesAndNumberFormats
ElseIf (Sheets("Location").Cells(i, 12) = "") And (Sheets("Location").Cells(i, 13) <> "") And (lastRow <> 53) Then
Sheets("Location").Cells(i, 1).Copy
Sheets("Supply Usage Form").Range("B22").End(xlDown).Offset(1, 0).PasteSpecial xlPasteValuesAndNumberFormats
Sheets("Location").Cells(i, 2).Copy
Sheets("Supply Usage Form").Range("B22").End(xlDown).Offset(0, 1).PasteSpecial xlPasteValuesAndNumberFormats
Sheets("Location").Cells(i, 13).Copy
Sheets("Supply Usage Form").Range("B22").End(xlDown).Offset(0, 6).PasteSpecial xlPasteValuesAndNumberFormats
ElseIf (Sheets("Location").Cells(i, 12) <> "") And (Sheets("Location").Cells(i, 13) <> "") And (lastRow <> 53) Then
Sheets("Location").Cells(i, 1).Copy
Sheets("Supply Usage Form").Range("B22").End(xlDown).Offset(1, 0).PasteSpecial xlPasteValuesAndNumberFormats
Sheets("Location").Cells(i, 2).Copy
Sheets("Supply Usage Form").Range("B22").End(xlDown).Offset(0, 2).PasteSpecial xlPasteValuesAndNumberFormats
Sheets("Location").Cells(i, 12).Copy
Sheets("Supply Usage Form").Range("B22").End(xlDown).Offset(0, 5).PasteSpecial xlPasteValuesAndNumberFormats
Sheets("Location").Cells(i, 13).Copy
Sheets("Supply Usage Form").Range("B22").End(xlDown).Offset(0, 6).PasteSpecial xlPasteValuesAndNumberFormats
End If
Next i
Sheets("Supply Usage Form").Cells(6, 4).Value = Number_2 + Number_1
Application.ScreenUpdating = True
End Sub
Last edited by a moderator: