码迷,mamicode.com
首页 > 编程语言 > 详细

VBA第七课

时间:2018-11-30 00:37:26      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:需要   row   完成   可见   int   sel   工作表   app   end   

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第七课

标签:需要   row   完成   可见   int   sel   工作表   app   end   

原文地址:https://www.cnblogs.com/yigeduanpian/p/10041744.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!