text 月报告(excel vba)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text 月报告(excel vba)相关的知识,希望对你有一定的参考价值。

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row = 3 And Target.Column = 9 Then
    For Each sh In Worksheets
        If Val(sh.Name) <> 0 Then
        sh.Range("o2:q2").EntireColumn.Hidden = False
        sh.Rows("3:3").RowHeight = 87
        dateS = DateSerial(CInt(Target.Value), CInt(sh.Name), 1)
            sh.Range("B1").Value = dateS
            sh.Range("C2").Value = dDate(dateS)
            sh.Range("C3").Value = "Остаки " & Format(mond(dateS), "d mmm")
            sh.Range("F2").Value = dDate(dateS, 7)
            sh.Range("F3").Value = "Остатки " & Format(mond(dateS, 7), "d mmm")
            sh.Range("I2").Value = dDate(dateS, 14)
            sh.Range("I3").Value = "Остатки " & Format(mond(dateS, 14), "d mmm")
            sh.Range("L2").Value = dDate(dateS, 21)
            sh.Range("L3").Value = "Остатки " & Format(mond(dateS, 21), "d mmm")
            sh.Range("O2").Value = IIf(CInt(Month(mond(dateS, 28))) <> sh.Name, "", dDate(dateS, 28))
            sh.Range("U2").Value = "ИТОГО   за  " & Format(dateS, "mmmm yyyy")
         If sh.Range("o2").Value = "" Then
            sh.Range("o2:q2").EntireColumn.Hidden = True
         End If
        End If
    Next sh
End If
End Sub

Private Function dDate(ByVal mDate As Date, Optional dCount As Integer = 0) As String
    FirstDayMonth = Format(mDate, "d")
      dDate = FirstDayMonth & " - " & Format(mond(mDate, dCount), "d mmm")
End Function
Private Function mond(ByVal mDate As Date, Optional dCount As Integer = 0) As String
    mond = IIf(WorksheetFunction.Weekday(mDate, 2) = 1, mDate, mDate + (8 - WorksheetFunction.Weekday(mDate, 2))) + dCount
End Function

以上是关于text 月报告(excel vba)的主要内容,如果未能解决你的问题,请参考以下文章

GROUP BY 月报告上的 MS Access 过滤器日期范围

工作要结果不要过程?数据分析不再用Python +Excel VBA!

text 通过Excel VBA.bas调用PowerPoint

如何在excel的vba中进行繁简转换

Excel vba 将数字转换成字符串的函数是哪个

Excel中怎样通过vba快速标注哪些单元格的数据发生变化?