我正在使用VBA填充电子表格。该VBA在最后一行写入了一个公式,但其格式设置为不提供0值,因此仅当其值大于1时才会填充。
假设它复制了100行,如何找到最后一个动态行,然后填充下面的行?
这是总计行。我可以复制下来,但不能确定最后一行以及如何填充它。
我发现的所有内容都给了我最后一行,但是它并没有告诉我如何在VBA中使用该信息。
示例-
如果A1:A100 = 1
A101 =总计100
Sub ButtonMacroLatest()
'Hide alerts
Application.DisplayAlerts = False
'
' Macro8 Macro
'
'Save to users device
ChDir "U:\WINDOWS"
ActiveWorkbook.SaveAs Filename:="U:\WINDOWS\OrderForm.xlsx", FileFormat:= _
xlOpenXMLWorkbook, CreateBackup:=False
'Create new workbook and populate
Workbooks.Add
ActiveCell.FormulaR1C1 = "MSG"
Range("B1").FormulaR1C1 = "=[OrderForm.xlsx]Order!R[1]C"
Range("C1").FormulaR1C1 = "=[OrderForm.xlsx]Order!R[1]C[3]"
Range("D1").FormulaR1C1 = "1400008000"
Range("E1").FormulaR1C1 = "501346009175"
Range("F1").FormulaR1C1 = "=TODAY()"
Range("G1").FormulaR1C1 = "=Now()"
Selection.NumberFormat = "[$-x-systime]h:mm:ss AM/PM"
Range("A2").FormulaR1C1 = "HDR"
Range("B2").FormulaR1C1 = "C"
Range("C2").FormulaR1C1 = "=[OrderForm.xlsx]Order!R4C2"
Range("G2").FormulaR1C1 = "=[OrderForm.xlsx]Order!R[1]C[3]"
Range("H2").FormulaR1C1 = "=[OrderForm.xlsx]Order!R2C4"
Range("K2").FormulaR1C1 = "STD"
Range("L2").FormulaR1C1 = "=[OrderForm.xlsx]Order!R5C2"
Range("N2").FormulaR1C1 = "=[OrderForm.xlsx]Order!R7C2"
Range("O2").FormulaR1C1 = "=[OrderForm.xlsx]Order!R8C2"
Range("Q2").FormulaR1C1 = "=[OrderForm.xlsx]Order!R9C2"
Range("R2").FormulaR1C1 = "=[OrderForm.xlsx]Order!R12C2"
Range("A3").FormulaR1C1 = "POS"
Range("B3").FormulaR1C1 = "=Row()*10-20"
Range("C3").FormulaR1C1 = "=[OrderForm.xlsx]Order!R[15]C[3]"
Range("D3").FormulaR1C1 = "=[OrderForm.xlsx]Order!R[15]C[1]"
Range("E3").FormulaR1C1 = "=[OrderForm.xlsx]Order!R[15]C[2]"
Range("F3").FormulaR1C1 = "=[OrderForm.xlsx]Order!R[15]C[5]"
Range("G3").FormulaR1C1 = "=[OrderForm.xlsx]Order!R[15]C[7]"
Range("H3").FormulaR1C1 = "GBP"
Range("L3").FormulaR1C1 = "TRA"
Range("M3").FormulaR1C1 = "=COUNTIF(C[-3], ""POS"")+COUNTIF(C[-3], ""HDR"")"
'Fills column to last row of data from Cell C15
Dim LastRow As Long
LastRow = Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Range("C15:C" & LastRow).FillDown
Range("D15:D" & LastRow).FillDown
Range("E15:E" & LastRow).FillDown
'Preformat cells to remove 0 value
Range("A1:Z1000").Select
Range("Z1000").Activate
Selection.NumberFormat = "#;#;"
'Finds the last non-blank cell on a sheet/range.
Range("C" & LastRow + 1).Formula = "=[OrderForm.xlsx]Order!R[15]C[7]"
'Reinstate alerts
Application.DisplayAlerts = True
MsgBox "We have saved a copy of your order form to your computer at C:\X\X"
End Sub
我已经尝试过给出的建议,但是它没有填充任何内容。当然,我对此做了些微修改以引用另一张纸。
抄写C:E的行是数字部件号。现在,底部的总数将是已填充行的数量。我该怎么做?抱歉,移动球门柱时,它只是在我刚开会时的一次对话中出现的。
答案 0 :(得分:2)
Range("A" & LastRow)
,其中LastRow
是包含所讨论的最后一行(在您的示例中为100)的变量
下面的行:Range("A" & LastRow + 1)
总和:Range("A" & LastRow + 1).Formula = "=SUM(A1:A" & LastRow & ")"