I have been searching for an answer to this for a while and have gotten very close.
In short I have a form which contains various columns. One of those being a quantity. This column would always have a value as if no quantity it will stay blank. However if the cell is populated with a value I then need to copy the entire row of formula to the row beneath.
I came across the following on here this morning which is the closest I have come yet, but I don't understand enough of the code to make it fit my needs (or perhaps it isn't even the best method?)
Code I found:
Sub SmartCopy()
Dim s1 As Worksheet, s2 As Worksheet
Dim N As Long, i As Long, j As Long
Set s1 = Sheets("Order")
Set s2 = Sheets("Converted")
N = s1.Cells(Rows.Count, "C").End(xlUp).Row
j = 1
For i = 1 To N
If s1.Cells(i, "C").Value = "" Then
Else
s1.Cells(i, "C").EntireRow.Copy s2.Cells(j, l)
j = j + 1
End If
Next i
End Sub
On my form the quantity starts at E15 (with the parts being ordered being in the columns before hand). If E15 has a value then the formula should copy to the next row and so on. If the next row quantity is blank then I need to remove any formula entered. So in essence only filling down if there is a value in the quantity on the original sheet as there is one row to be put at the end too. I can do the final part, but any code I've found previously enters formula, so of course the cell is then not blank and causing other problems, hence asking if it can be done this way instead?.
This is a copy of the form. You will note the values start at A15 for the part No's, and the whole row of info would be needed if anything is ordered on the next row.
This is the converted version, as you see it populates through, but I need to copy down as described.
The rest of my code works, it is just this section I am having issues with. Current full code -
Sub ButtonMacro()
'Hide alerts
Application.DisplayAlerts = False
'Add new sheet for table
Sheets.Add.Name = "Converted"
'Populate new worksheet
Range("A1").Formula = "MSG"
Range("B1").Formula = "=Order!F2"
Range("C1").Formula = "ORDER"
Range("D1").Formula = "1400008000"
Range("E1").Formula = "501346009175"
Range("F1").Formula = "=TODAY()"
Range("F1").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("G1").Formula = "=Now()"
Range("G1").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Selection.NumberFormat = "[$-x-systime]h:mm:ss AM/PM"
Range("A2").Formula = "HDR"
Range("B2").Formula = "C"
Range("C2").Formula = "1400011281"
Range("G2").Formula = "=Order!F2"
Range("H2").Formula = "=Order!D2"
Range("K2").Formula = "STD"
Range("L2").Formula = "=Order!F5"
Range("N2").Formula = "=Order!F7"
Range("O2").Formula = "=Order!F8"
Range("Q2").Formula = "=Order!F9"
Range("R2").Formula = "=Order!F12"
Range("A3").Formula = "POS"
Range("B3").Formula = "=ROW()*10-20"
Range("B3").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("C3").Formula = "=Order!C15"
Range("D3").Formula = "=Order!A15"
Range("E3").Formula = "=Order!B15"
Range("F3").Formula = "=Order!E15"
Range("G3").Formula = "=Order!G15"
Range("H3").Formula = "=IF(Order!H15<1,"""",""GBP"")"
Range("M3").Formula = "=COUNTIF(C[-3], ""POS"")+COUNTIF(C[-3], ""HDR"")"
'Fills column to last row of data from Cell C3
Dim LastRow As Long
LastRow = Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Range("C3:H3" & LastRow).FillDown
'Find last blank in A and fill with TRA
Cells(Application.Evaluate("MAX(IF(C3:C2000<>"""",ROW(c3:c2000)),0,1)"), "A").Select
ActiveCell = "TRA"
'Format cells to remove 0 value
Range("A1:Z1000").Select
Range("Z1000").Activate
Selection.NumberFormat = "#;#;"
'Reinstate alerts
Application.DisplayAlerts = True
MsgBox "We have saved a copy of your order form to your computer at C:\X\X"
End Sub
The section "'Fills column to last row of data from Cell C3" is what currently doesn't do what I need.
Edit: I should also add, any number of parts could be ordered, so I can't specify row to row, it could be one part, it could be 1000.
Examples:
Client form filled out ready to be converted
Converted form (the yellow is what I'm trying to get rid of)
So in the converted version you will see TRA on row 33. This is because the current method is copying down and looking for the next blank cell, as they have formula in they aren't blank hence asking if it can be done this way instead. I hope that helps?