tranhuunhanhvnh
Thành viên mới
- Tham gia
- 11/7/19
- Bài viết
- 3
- Được thích
- 0
Sub xuat_cbtd()
Dim sh As Worksheet, shNew As Worksheet
Dim rng As Range
Dim c As Range
Dim item As Variant
Set sh = Sheet1
sh.AutoFilterMode = False
Set rng = sh.Range("G4:G" & sh.Range("A" & Rows.Count).End(xlUp).Row)
Dim dict
Set dict = CreateObject("Scripting.Dictionary")
For Each c In rng
dict(c.Value) = ""
Next c
Set rng = sh.Range("A3:AI" & sh.Range("A" & Rows.Count).End(xlUp).Row)
Dim key
For Each key In dict.keys
Set shNew = Worksheets.Add(After:=Worksheets(Worksheets.Count))
shNew.Name = key
With rng
.AutoFilter Field:=7, Criteria1:=key
.SpecialCells(xlCellTypeVisible).Copy
shNew.Range("A1").PasteSpecial xlPasteFormats
shNew.Range("A1").PasteSpecial xlPasteColumnWidths
shNew.Range("A1").PasteSpecial xlPasteValues
sh.AutoFilterMode = False
Application.CutCopyMode = False
End With
Next
sh.Activate
rng.AutoFilter
Application.ScreenUpdating = True
End Sub
Nhờ mọi người giúp đỡ sữa giúp mình với ạ
Dim sh As Worksheet, shNew As Worksheet
Dim rng As Range
Dim c As Range
Dim item As Variant
Set sh = Sheet1
sh.AutoFilterMode = False
Set rng = sh.Range("G4:G" & sh.Range("A" & Rows.Count).End(xlUp).Row)
Dim dict
Set dict = CreateObject("Scripting.Dictionary")
For Each c In rng
dict(c.Value) = ""
Next c
Set rng = sh.Range("A3:AI" & sh.Range("A" & Rows.Count).End(xlUp).Row)
Dim key
For Each key In dict.keys
Set shNew = Worksheets.Add(After:=Worksheets(Worksheets.Count))
shNew.Name = key
With rng
.AutoFilter Field:=7, Criteria1:=key
.SpecialCells(xlCellTypeVisible).Copy
shNew.Range("A1").PasteSpecial xlPasteFormats
shNew.Range("A1").PasteSpecial xlPasteColumnWidths
shNew.Range("A1").PasteSpecial xlPasteValues
sh.AutoFilterMode = False
Application.CutCopyMode = False
End With
Next
sh.Activate
rng.AutoFilter
Application.ScreenUpdating = True
End Sub
Nhờ mọi người giúp đỡ sữa giúp mình với ạ