VBA第七课
Posted yigeduanpian
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VBA第七课相关的知识,希望对你有一定的参考价值。
Sub shishi() Dim k, i, j As Integer Dim sht As Worksheet For i = 1 To Sheet1.Range("a65536").End(xlUp).Row k = 0 ‘事件赋值 用于发生于不发生指代 For Each sht In Sheets If sht.Name = Sheet1.Range("a" & i) Then k = 1 End If Next If k = 0 Then Sheets.Add after:=Sheets(Sheets.Count) Sheets(Sheets.Count).Name = Sheet1.Range("a" & i) End If Next End Sub
Sheet1.Activate
Sheet1.Range("a1").Select ‘选择前需要先激活
application.goto Sheets(1).Range("A1") ‘激活工作表和选择单元格在同一语句完成
Resize(2, 3).Select ‘resize只对于单元格 不对于可见区域
Sub shishi() Dim i As Integer Dim sht As Worksheet For i = 2 To Sheet1.Range("a65536").End(xlUp).Row ‘单元格循环 k = 0 For Each sht In Sheets If sht.Name = Sheet1.Range("d" & i) Then k = 1 End If Next If k = 0 Then Sheets.Add after:=Sheets(Sheets.Count) Sheets(Sheets.Count).Name = Sheet1.Range("d" & i) End If Next For Each sht In Sheets If sht.Name <> "数据" Then sht.Cells.ClearContents End If Sheet1.Activate ‘选择前需要先激活 Sheet1.Range("a1").Select Selection.AutoFilter ActiveSheet.Range("A1").AutoFilter Field:=4, Criteria1:=sht.Name Cells.Select If sht.Name <> "数据" Then Selection.Copy Sheets(sht.Name).Range("a1") End If Next Sheet1.Activate Sheet1.Range("a1").Select Selection.AutoFilter End Sub
Sub shishi() Dim i As Integer Dim sht As Worksheet Sheet1.Cells.ClearContents Sheet2.Range("a1").EntireRow.Copy Sheet1.Range("a1") For Each sht In Sheets For i = 2 To sht.Range("a65536").End(xlUp).Row If sht.Name <> "数据" Then sht.Range("a" & i).EntireRow.Copy Sheet1.Range("a" & Sheet1.Range("a65536").End(xlUp).Row + 1) End If Next Next End Sub
以上是关于VBA第七课的主要内容,如果未能解决你的问题,请参考以下文章