我目前面临的问题是我称之为“更新”(已经写过)的模块中的子程序,我想做以下事情;
选择“Sheet2”表单数据(一行,A4:KL4)并按顺序将“主”表复制到其上面记录的数据。
子程序还需要包括另一个功能,即搜索“主”表格中的参考编号的先前条目,并且如果参考编号尚不存在,则仅复制“Sheet2”行数据。
如果参考编号已经存在,那么它需要检查上一个条目的日期。如果它是相同的日期,那么我希望子程序覆盖已经保存的内容。如果日期不同,那么我希望子过程将“Sheet2”表单添加到新行。
如果有人可以提供帮助,我将非常感激。我已经检查了其他帖子,甚至尝试使用以前答案中的一些代码,但它似乎对我没用。
Sub update1()
Sheets("loading").Select
Application.ScreenUpdating = False
Sheets("Current Audit").Select
Range("J76").Select
Selection.Copy
Range("AG4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("J77").Select
Application.CutCopyMode = False
Selection.Copy
Range("AF4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("B75").Select
Selection.Copy
Range("Q4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("B76").Select
Selection.Copy
Range("R4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("B77").Select
Selection.Copy
Range("S4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("B78").Select
Selection.Copy
Range("T4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("B79").Select
Selection.Copy
Range("U4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("B80").Select
Selection.Copy
Range("V4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("B81").Select
Selection.Copy
Range("W4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("B82").Select
Selection.Copy
Range("X4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("B83").Select
Selection.Copy
Range("Y4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("B84").Select
Selection.Copy
Range("Z4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("B85").Select
Selection.Copy
Range("AA4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("B86").Select
Selection.Copy
Range("AB4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("B87").Select
Selection.Copy
Range("AC4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Range("B88").Select
Selection.Copy
Range("AD4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("B89").Select
Selection.Copy
Range("AE4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("AF5").Select
ActiveCell.FormulaR1C1 = "=IF(R[-1]C=""N/A"",""N/A"",R[-1]C*100)"
Range("AG5").Select
ActiveCell.FormulaR1C1 = "=IF(R[-1]C=""N/A"",""N/A"",R[-1]C*100)"
Range("Q5").Select
ActiveCell.FormulaR1C1 = "=IF(R[-1]C=""N/A"",""N/A"",R[-1]C*100)"
Range("R5").Select
ActiveCell.FormulaR1C1 = "=IF(R[-1]C=""N/A"",""N/A"",R[-1]C*100)"
Range("S5").Select
ActiveCell.FormulaR1C1 = "=IF(R[-1]C=""N/A"",""N/A"",R[-1]C*100)"
Range("T5").Select
ActiveCell.FormulaR1C1 = "=IF(R[-1]C=""N/A"",""N/A"",R[-1]C*100)"
Range("U5").Select
ActiveCell.FormulaR1C1 = "=IF(R[-1]C=""N/A"",""N/A"",R[-1]C*100)"
Range("V5").Select
ActiveCell.FormulaR1C1 = "=IF(R[-1]C=""N/A"",""N/A"",R[-1]C*100)"
Range("W5").Select
ActiveCell.FormulaR1C1 = "=IF(R[-1]C=""N/A"",""N/A"",R[-1]C*100)"
Range("X5").Select
ActiveCell.FormulaR1C1 = "=IF(R[-1]C=""N/A"",""N/A"",R[-1]C*100)"
Range("Y5").Select
ActiveCell.FormulaR1C1 = "=IF(R[-1]C=""N/A"",""N/A"",R[-1]C*100)"
Range("Z5").Select
ActiveCell.FormulaR1C1 = "=IF(R[-1]C=""N/A"",""N/A"",R[-1]C*100)"
Range("AA5").Select
ActiveCell.FormulaR1C1 = "=IF(R[-1]C=""N/A"",""N/A"",R[-1]C*100)"
Range("AB5").Select
ActiveCell.FormulaR1C1 = "=IF(R[-1]C=""N/A"",""N/A"",R[-1]C*100)"
Range("AC5").Select
ActiveCell.FormulaR1C1 = "=IF(R[-1]C=""N/A"",""N/A"",R[-1]C*100)"
Range("AD5").Select
ActiveCell.FormulaR1C1 = "=IF(R[-1]C=""N/A"",""N/A"",R[-1]C*100)"
Range("AE5").Select
ActiveCell.FormulaR1C1 = "=IF(R[-1]C=""N/A"",""N/A"",R[-1]C*100)"
Range("GA5").Select
ActiveCell.FormulaR1C1 = "=IF(R[-1]C=""N/A"",""N/A"",R[-1]C*100)"
Range("GE5").Select
ActiveCell.FormulaR1C1 = "=IF(R[-1]C=""N/A"",""N/A"",R[-1]C*100)"
Range("GI5").Select
ActiveCell.FormulaR1C1 = "=IF(R[-1]C=""N/A"",""N/A"",R[-1]C*100)"
Range("GM5").Select
ActiveCell.FormulaR1C1 = "=IF(R[-1]C=""N/A"",""N/A"",R[-1]C*100)"
Range("GP5").Select
ActiveCell.FormulaR1C1 = "=IF(R[-1]C=""N/A"",""N/A"",R[-1]C*100)"
Range("GR5").Select
ActiveCell.FormulaR1C1 = "=IF(R[-1]C=""N/A"",""N/A"",R[-1]C*100)"
Range("GU5").Select
ActiveCell.FormulaR1C1 = "=IF(R[-1]C=""N/A"",""N/A"",R[-1]C*100)"
Range("GW5").Select
ActiveCell.FormulaR1C1 = "=IF(R[-1]C=""N/A"",""N/A"",R[-1]C*100)"
Range("GZ5").Select
ActiveCell.FormulaR1C1 = "=IF(R[-1]C=""N/A"",""N/A"",R[-1]C*100)"
Range("HB5").Select
ActiveCell.FormulaR1C1 = "=IF(R[-1]C=""N/A"",""N/A"",R[-1]C*100)"
Range("HE5").Select
ActiveCell.FormulaR1C1 = "=IF(R[-1]C=""N/A"",""N/A"",R[-1]C*100)"
Range("HH5").Select
ActiveCell.FormulaR1C1 = "=IF(R[-1]C=""N/A"",""N/A"",R[-1]C*100)"
Range("HK5").Select
ActiveCell.FormulaR1C1 = "=IF(R[-1]C=""N/A"",""N/A"",R[-1]C*100)"
End Sub
答案 0 :(得分:0)
我更喜欢先将数据保存到数组中,然后对其进行操作,然后将结果转储到新范围内。一般来说,数组操作更容易,更快。同时,创建公式数组要容易得多(在您的情况下是一个数组: “= IF(R [-1] C =” “N / A”, “ ”“ N / A ”“,R [-1] C * 100)”
e.g。
Dim YourArrayContainingFormulas() As Variant
Redim YourArrayContainingFormulas(1 to 10)
For i = 1 To 10
YourArrayContainingFormulas(i)="=YourFormula"
Next i
并将其复制到所选范围内:
With ActiveCell
Range(.Offest(0,0),.Offset(0,9)).Value=YourArrayContainingFormulas
End With