从添加纸张的单元格中对纸张求和

时间:2015-07-24 04:10:24

标签: excel-vba vba excel

我正在寻找如何在当前的添加表单中加总,然后在表格中显示总数" Mytotal"

我的标签页如下所示:

... 2015年9月4日至2015年9月5日,2015年9月6日,制作,Mytotal ..

当我运行我的宏时,它会复制工作表" Production"并按照以下顺序重命名为一天,并在工作表中清除单元格" Productions"。

我正在寻找的是如何将下一个添加工作表总结为 Sep-07-2015,Productions,.. ,当我运行我的宏时,我需要的是: 片"制作" A2 + A3 - Sheet" Sep-06-2015" A1,以及表格中的总显示" Mytotal"

1 个答案:

答案 0 :(得分:0)

在这里,我的方法是:

Public Sub copyAndExecute()

    Dim lastDateSheet As Date
    Dim productionIndex  As Integer
    Dim newSheetName As String

    'get sheet index of "Production" sheet
    productionIndex = Sheets("Productions").Index

    'get last sheet name which is date
    lastDateSheet = Sheets(productionIndex - 1).Name

    'Copy "Production" sheet before it
    Worksheets("Productions").Copy Before:=Worksheets("Productions")

    'Get new sheet name by adding one day
    newSheetName = Format(DateAdd("d", 1, CDate(lastDateSheet)), "MMM-dd-yyyy")

    'Rename new sheet
    Sheets(productionIndex).Name = newSheetName

    'Clear content
    Sheets(productionIndex).Cells.Clear

    'Execute cells
    Sheets("Mytotal").Range("A1") = Sheets("Productions").Range("A2") + Sheets("Productions").Range("A3") - Sheets(productionIndex - 2).Range("A1")

End Sub