以下是计算日期差异的程序。在单元格和列之间,然后在列中进行小计算,然后过滤库存直到特定日期(这是用于计算日期的相同日期。在程序的第一行中的差异。在程序中,我是没有得到计算操作的结果。我只得到0作为答案只有一个单元格。可以帮助识别问题。
Sub Filter_RPCALC()
'Calculation of Date Diff.
Range("N2").Formula = "=DAYS($A$590,D2)"
Range("N2").AutoFill Destination:=Range("N2:N585"), Type:=xlFillDefault
'Calculation of Rp
Dim Rp As Integer
Dim var1 As Integer
Dim var2 As Integer
Dim var3 As Integer
var1 = Range("M2:M585").Select
var2 = Range("02:0585").Select
var3 = Range("L2:L585").Select
Rp = var1 * var2 + var3
Range("P2:P585").Select
ActiveCell.FormulaR1C1 = Rp
'Filter the coils for Deliver Date
ActiveSheet.Range("$G$1:$G$585").AutoFilter Field:=1, Criteria1:="<" & CLng(Range("A590"))
End Sub
答案 0 :(得分:1)
尽量不要使用Select
。试试这个:
Sub Filter_RPCALC()
Dim was As Worksheet
'Calculation of Date Diff.
Range("N2").Formula = "=DAYS($A$590,D2)"
Range("N2").AutoFill Destination:=Range("N2:N585"), Type:=xlFillDefault
'Calculation of Rp
Dim var1 As Variant, var2 As Variant, var3 As Variant
Dim Rp As Variant
Dim i As Long
var1 = Range("M2:M585").Value
var2 = Range("02:0585").Value
var3 = Range("L2:L585").Value
Rp = var1
For i = LBound(Rp,1) To UBound(Rp,1)
Rp(i,1) = var1(i,1)*var2(i,1) + var3(i,1)
Next i
Range("P2:P585").Value = Rp
'Filter the coils for Deliver Date
ActiveSheet.Range("$G$1:$G$585").AutoFilter Field:=1, Criteria1:="<" & CLng(Range("A590"))
Set ws = ThisWorkbook.Sheets.Add(After:= ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count))
ActiveSheet.Range("G1:G585").SpecialCells(xlCellTypeVisible).Copy Destination:=ws.Range("A1")
End Sub