如何用VBA代码生成多个工作表并将指定的内容填充到相应的工作表中

动态 未结 0 92
小小草
小小草 LV1 2023年9月23日 23:40 发表
以下是使用VBA代码生成多个工作表并将指定内容填充到相应工作表中的示例代码: ```vba Sub CreateWorksheets() Dim wb As Workbook Set wb = ThisWorkbook ' 创建3个工作表 Dim ws1 As Worksheet Set ws1 = wb.Sheets.Add(After:=wb.Sheets(wb.Sheets.Count)) ws1.Name = "Sheet1" Dim ws2 As Worksheet Set ws2 = wb.Sheets.Add(After:=wb.Sheets(wb.Sheets.Count)) ws2.Name = "Sheet2" Dim ws3 As Worksheet Set ws3 = wb.Sheets.Add(After:=wb.Sheets(wb.Sheets.Count)) ws3.Name = "Sheet3" ' 在Sheet1中填充数据 ws1.Range("A1").Value = "姓名" ws1.Range("B1").Value = "年龄" ws1.Range("C1").Value = "性别" ws1.Range("A2").Value = "张三" ws1.Range("B2").Value = 20 ws1.Range("C2").Value = "男" ws1.Range("A3").Value = "李四" ws1.Range("B3").Value = 25 ws1.Range("C3").Value = "女" ' 在Sheet2中填充数据 ws2.Range("A1").Value = "学科" ws2.Range("B1").Value = "分数" ws2.Range("A2").Value = "语文" ws2.Range("B2").Value = 90 ws2.Range("A3").Value = "数学" ws2.Range("B3").Value = 85 ' 在Sheet3中填充数据 ws3.Range("A1").Value = "日期" ws3.Range("B1").Value = "销售额" ws3.Range("A2").Value = "2021-01-01" ws3.Range("B2").Value = 1000 ws3.Range("A3").Value = "2021-01-02"
收藏(0)  分享
相关标签: 智能问答
问题没解决?让AI助手帮你作答 AI助手
0个回复
  • 消灭零回复