Home > Software engineering >  Vba to perform in accordance with the conditions of classification, automatically remove existing mo
Vba to perform in accordance with the conditions of classification, automatically remove existing mo

Time:09-29

An execution, according to the condition classification
Classification (Sub)
Dim sh As Worksheet, d As Object, ary, aryB, SJL As Long, fenlei
SJL=[a65536]. End (3). The Row
The Set d=CreateObject (" scripting. The dictionary ")
Ary=Range (A2: "J" & amp; SJL)
For I=1 To SJL - 1
D (ary (I, 1))=""
Next
AryB=d.k eys
For fenlei=LBound (aryB) To UBound (aryB)
The Set sh=Worksheets. The Add (after:=Worksheets (Worksheets. Count))
Sh. Name=aryB (fenlei)
Sheet1. Range (" ""). Copy sh. Range (" ")
For sj=2 To SJL
Cc=Application. CountA (sh) Range (A: A)) + 1
If ary (sj - 1, 10)=aryB (fenlei) Then
Sheet1. Rows (sj). Copy sh. Rows (cc)
End the If
Next sj
Next fenlei
End Sub
Second, delete the work except 1 table
Sub removed except 1 worksheet ()
L=Sheets. Count
For I=l To Step 2-1
Application. DisplayAlerts=False
Sheets (I). The Delete
Application. DisplayAlerts=True
Next
End Sub

1. The above code changes, making the classification in the implementation of the deleted except 1 worksheet at the same time, that is as long as one step can achieve these two functions at the same time,
2. The title line 2 line, from line 3 classification, this code seems to start from line 2 classification, how to change

CodePudding user response:

 
Sub combined ()
Dim sh As Worksheet, d As Object, ary, aryB, SJL As Long, fenlei
SJL=[a65536]. End (3). The Row
The Set d=CreateObject (" scripting. The dictionary ")
Ary=Range (A2: "J" & amp; SJL)
For I=1 To SJL - 1
D (ary (I, 1))=""
Next
AryB=d.k eys
For fenlei=LBound (aryB) To UBound (aryB)
The Set sh=Worksheets. The Add (after:=Worksheets (Worksheets. Count))
Sh. Name=aryB (fenlei)
Sheet1. Range (" ""). Copy sh. Range (" ")
For sj=2 To SJL
Cc=Application. CountA (sh) Range (A: A)) + 1
If ary (sj - 1, 10)=aryB (fenlei) Then
Sheet1. Rows (sj). Copy sh. Rows (cc)
End the If
Next sj
Next fenlei

L=Sheets. Count
For I=l To Step 2-1
Application. DisplayAlerts=False
Sheets (I). The Delete
Application. DisplayAlerts=True
Next
End Sub
  •  Tags:  
  • VBA
  • Related