计算网络天数,从例外中省略一些日期 - Excel

时间:2013-06-12 13:25:13

标签: excel vba

以下是一个宏,它从我们导入某些标签的数据中收集数据。运行宏时,它会过滤数据并生成包含此新数据的新Excel工作簿。创造这个的人不再和我们在一起了。该宏工作正常,除了我尝试添加另一列,就像计算网络天数一样,称为自第一次授权停放以来的天数。我想添加另一个,从传递给我们的信息开始以来几天。即第1列调用指示较少停放。

Sub Runme()
'
' Macro1 Macro
' Macro recorded 22/03/2013'

'
    Sheets("CCX data SORTED").Select
    Cells.Select
    Selection.Delete Shift:=xlUp
    Sheets("CCX Data Raw").Select
    Range("A:C,E:G").Select
    Selection.Delete Shift:=xlToLeft
    Rows("1:1").Select
    Selection.AutoFilter
    Range("H2").Select
    Range("A1:X10000").Sort Key1:=Range("H1"), Order1:=xlDescending, Header:= _
        xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal
    Range("H55000").End(xlUp)(2, 1).Select
    Range(Selection, Selection.End(xlToLeft)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToLeft)).Select
    Selection.ClearContents
    Cells.Select
    Selection.Copy
    Sheets("CCX data SORTED").Select
    Range("A1").Select
    ActiveSheet.Paste
    Sheets("CCX Data Raw").Select
    Cells.Select
    Selection.Delete Shift:=xlUp
    Sheets("CCX data SORTED").Select
    Columns("X:X").Select
    Selection.Insert Shift:=xlToRight
    Range("X2").Select
    ActiveCell.FormulaR1C1 = _
        "=IF(VLOOKUP(RC[-23],'SCMT weekly data'!C[-17]:C[-11],7,FALSE)>0,(VLOOKUP(RC[-23],'SCMT weekly data'!C[-17]:C[-11],7,FALSE)),"""")"
    Range("X2").Select
    Selection.AutoFill Destination:=Range("X2:X5000")
    Range("X1").Select
    ActiveCell.FormulaR1C1 = "SCMT end Date"
    Columns("X:X").Select
    Selection.NumberFormat = "m/d/yyyy"
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Sheets("SCMT Weekly data").Select
    Columns("Z:Z").Select
    Selection.Insert Shift:=xlToRight
    Range("Z1").Select
    ActiveCell.FormulaR1C1 = "Days To Exclude 1"
    Range("Z2").Select
    ActiveCell.FormulaR1C1 = _
        "=IF(COUNTA(RC[-2],RC[-1])=2,NETWORKDAYS(RC[-2],RC[-1],'Bank hols'!RC[-25]:R[56]C[-25]),0)"
    Selection.AutoFill Destination:=Range("Z2:Z5000"), Type:=xlFillDefault
    Columns("AD:AD").Select
    Selection.Insert Shift:=xlToRight
    Range("AD1").Select
    ActiveCell.FormulaR1C1 = "Days To Exclude 2"
    Range("AD2").Select
    ActiveCell.FormulaR1C1 = _
        "=IF(COUNTA(RC[-2],RC[-1])=2,NETWORKDAYS(RC[-2],RC[-1],'Bank hols'!RC[-29]:R[56]C[-29]),0)"
    Selection.AutoFill Destination:=Range("AD2:AD5000")
    Columns("Z:Z").Select
    Selection.NumberFormat = "0"
    Columns("AD:AD").Select
    Selection.NumberFormat = "0"
    Range("AH2").Select
    ActiveCell.FormulaR1C1 = "=TODAY()"
    Range("AF1").Select
    ActiveCell.FormulaR1C1 = "Days since first auth"
    Range("AF2").Select
    ActiveCell.FormulaR1C1 = _
        "=IF(COUNTA(RC[-21],R2C34)=2,NETWORKDAYS(RC[-21],R2C34,'Bank hols'!RC[-31]:R[56]C[-31]),"""")"
    Range("AG2").Select
    ActiveCell.FormulaR1C1 = _
        "=IF(ISNUMBER(RC[-1]),SUM(RC[-1]-(RC[-3]+RC[-7])),"""")"
    Range("AG1").Select
    ActiveCell.FormulaR1C1 = "Days since 1st Auth less parked"
    Columns("AH:AH").Select
    Selection.Insert Shift:=xlToRight
    Range("AH1").Select
    ActiveCell.FormulaR1C1 = "Still Parked"
    Range("AH2").Select
    ActiveCell.FormulaR1C1 = _
        "=IF(AND(ISNUMBER(RC[-10]),ISBLANK(RC[-9])),""XX"",IF(AND(ISNUMBER(RC[-6]),ISBLANK(RC[-5])),""XX"",""""))"
    Selection.AutoFill Destination:=Range("AH2:AH5000")
    Range("AF2:AG2").Select
    Selection.AutoFill Destination:=Range("AF2:AG5000")
    Range("A55000").End(xlUp)(2, 1).Select
    Selection.EntireRow.Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.ClearContents
    Sheets("CCX data SORTED").Select
    Range("Z1").Select
    ActiveCell.FormulaR1C1 = "SCMT Queue"
    Range("Z2").Select
    ActiveCell.FormulaR1C1 = _
        "=VLOOKUP(RC[-25],'SCMT Daily Drop'!C[-16]:C[-14],3,FALSE)"
    Selection.AutoFill Destination:=Range("Z2:Z5000")
    Range("AA1").Select
    ActiveCell.FormulaR1C1 = "Days Since First Approved"
    Range("AA2").Select
    ActiveCell.FormulaR1C1 = "=VLOOKUP(RC1,'SCMT weekly data'!C7:C34,27,FALSE)"
    Selection.AutoFill Destination:=Range("AA2:AA5000")
    Range("AB1").Select
    ActiveCell.FormulaR1C1 = "Still Parked"
    Range("AB2").Select
    ActiveCell.FormulaR1C1 = "=VLOOKUP(RC1,'SCMT weekly data'!C7:C34,28,FALSE)"
    Selection.AutoFill Destination:=Range("AB2:AB5000")
    Cells.Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("A55000").End(xlUp)(2, 1).Select
    Selection.EntireRow.Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.ClearContents
    Sheets("SCMT weekly data").Select
    Cells.Select
    Application.CutCopyMode = False
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        Sheets(Array("SCMT weekly data", "SCMT Daily Drop", "CCX data SORTED")).Select
    Sheets("CCX data SORTED").Activate
    Sheets(Array("SCMT weekly data", "SCMT Daily Drop", "CCX data SORTED")).Copy
    Windows("SCMT Parked.xls").Activate
    Sheets("SCMT weekly data").Select
    Cells.Select
    Selection.Delete Shift:=xlUp
    Sheets("SCMT Daily Drop").Select
    Cells.Select
    Selection.Delete Shift:=xlUp
    Sheets("CCX data SORTED").Select
    Cells.Select
    Selection.Delete Shift:=xlUp
    MsgBox ("Macro Complete")


End Sub

1 个答案:

答案 0 :(得分:0)

你想要它在哪里?例如,如果您想在z列中使用它,请尝试:

Columns("Z:Z").Select
Selection.Insert Shift:=xlToRight
Range("Z1").Select
ActiveCell.FormulaR1C1 = "New formula"
Range("Z2").Select
ActiveCell.FormulaR1C1 = "=AA2-AB2"
Selection.AutoFill Destination:=Range("Z2:Z5000")

我不明白你需要的公式,但是你可以使用一个模板...如果你给我们公式,我们可以把它放在第二行?