|
本帖最后由 yuyubiao 于 2023-4-28 11:22 编辑
- Sub GenerateNotification()
- '定义变量
- Dim wb As Workbook
- Dim wsSrc As Worksheet
- Dim wsDest As Worksheet
- Dim srcRowCount As Long, colCount As Long
- Dim destRowCount As Long, i As Long, j As Long
- Dim currentDate As String
- '获取当前日期
- currentDate = Format(Now(), "yyyymmdd")
- '打开工作簿和原始数据表格
- Set wb = ThisWorkbook
- Set wsSrc = wb.ActiveSheet
- '新建通知单工作表
- Set wsDest = wb.Sheets.Add(after:=wsSrc)
- wsDest.Name = "通知单" & currentDate
- '获取行数和列数
- srcRowCount = wsSrc.Cells(Rows.Count, 1).End(xlUp).Row
- colCount = wsSrc.Cells(1, Columns.Count).End(xlToLeft).Column
- For i = 2 To srcRowCount
-
- wsSrc.Range("A1", wsSrc.Cells(1, colCount)).Copy wsDest.Cells(destRowCount + 1, 1)
-
-
- wsSrc.Range(wsSrc.Cells(i, 1), wsSrc.Cells(i, colCount)).Copy wsDest.Cells(destRowCount + 2, 1)
- destRowCount = destRowCount + 2
-
-
- wsDest.Rows(destRowCount + 1).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
- destRowCount = destRowCount + 1
-
- Next i
- '删除最后插入的空白行
- wsDest.Rows(destRowCount + 1).Delete
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|