I am brand new to VBA and need some help with the below code. It works well and splits the data based on two filters, but does not preserve column width.
Could please someone assist and guide me?
Thank you.
Code
Sub ertert()
Dim x, i&, s$, d As Object
Set d = CreateObject("Scripting.Dictionary"): d.CompareMode = 1
Application.ScreenUpdating = 0
With Sheets("Raw data")
.AutoFilterMode = False
With .Range("A1:K" & .Cells(Rows.Count, 1).End(xlUp).Row)
x = .Value
For i = 2 To UBound(x)
s = x(i, 4) & " " & x(i, 5)
If Not d.Exists(s) Then
d.Item(s) = 1
If Not Evaluate("ISREF('" & s & "'!A1)") Then
Sheets.Add(after:=Sheets(Sheets.Count)).Name = s
Else
Sheets(s).UsedRange.ClearContents
End If
.AutoFilter Field:=4, Criteria1:=x(i, 4)
.AutoFilter Field:=5, Criteria1:=x(i, 5)
.Copy Sheets(s).Cells(1)
End If
Next i
.AutoFilter
End With
End With
Set d = Nothing
With Application
.CutCopyMode = False: .ScreenUpdating = True
End With
End Sub
Display More