Hi I was given a piece of code and told it would make my program run quicker but I don't really know how to implement my original code into the new piece. I have tried substituting pieces of code into it but I always get an error or the wrong outcome. If anyone could help me out with it I would be very grateful.
ORIGINAL CODE
Formula:
Sub splitSheets()
Dim i As Long, a, nome As String, ws As Worksheet
Application.ScreenUpdating = False
On Error Resume Next
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "WL1C FINAL REPORT" Then
ws.Cells.ClearContents
End If
Next
With Sheets("WL1C FINAL REPORT")
a = .Range("B7:B" & .Cells(.Rows.Count, 2).End(xlUp).Row)
For i = 1 To UBound(a)
If Trim(a(i, 1)) <> vbNullString Then
nome = Trim(a(i, 1))
If Not Evaluate("ISREF('" & nome & "'!A6)") Then 'A1 to A6
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = nome
End If
.Range("A6:S6").Copy Worksheets(nome).Range("A6") ' A1 to A6
.Cells(i + 6, 2).Resize(, 19).Copy '(i, 2) - i = the row to start on and 2 = the number of columns over to start pasting
Worksheets(nome).Range("B" & Rows.Count).End(xlUp)(2).PasteSpecial xlPasteAll
Worksheets(nome).EntireRow.AutoFit
Worksheets(nome).Columns("F").NumberFormat = "dd-mmm-yy"
Worksheets(nome).Columns("I").NumberFormat = "dd-mmm-yy"
Worksheets(nome).Columns("J").NumberFormat = "dd-mmm-yy"
Worksheets(nome).Columns("L").NumberFormat = "dd-mmm-yy" 'Date formats
Worksheets(nome).Columns("M").NumberFormat = "dd-mmm-yy"
Worksheets(nome).Columns("O").NumberFormat = "dd-mmm-yy"
End If
Next i
End With
Application.CutCopyMode = 0
Application.ScreenUpdating = True
End Sub
NEW LAYOUT
Formula:
Sub newSplitSheets()
Dim a, i As Long, j As Long, NR As Long, LR&, ws As Worksheet
Application.ScreenUpdating = False
On Error Resume Next
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "WL1C FINAL REPORT" Then
ws.Cells.ClearContents
End If
Next
With Worksheets("WL1C FINAL REPORT")
a = .Range("B7").CurrentRegion.Value
End With
For i = 7 To UBound(a)
If Not Evaluate("=ISREF(" & a(i, 2) & "!A6)") Then
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = a(i, 2)
End If
With Worksheets(a(i, 2))
NR = .Cells(Rows.Count, "B").End(xlUp).Row + 1
For j = 1 To UBound(a, 2)
.Cells(1, j) = a(6, j)
.Cells(NR, j) = a(i, j)
Next
End With
Next
End Sub
Bookmarks