Hello,
Having some intermittant problems with a macro I'm using to create individual sheets from a list - it autofilters to display each row, and copies the contents to a new sheet named after the "Name" column of the row.
Here is the portion of code that creates the sheets:
Dim rRange As Range, rCell As Range
Dim wSheet As Worksheet
Dim wSheetStart As Worksheet
Dim strText As String
On Error Resume Next
On Error GoTo 0
Set wSheetStart = activesheet
wSheetStart.AutoFilterMode = False
'Set a range variable to the correct item column
Set rRange = Range("A8:A150")
On Error Resume Next
With wSheetStart
For Each rCell In rRange
strText = rCell
If strText = "" Then Exit For
.Range("A8").AutoFilter 1, strText
Worksheets(strText).delete
'Add a sheet named as content of rCell
Worksheets.Add().Name = strText
' Copy the visible filtered range _
(default of Copy Method) And leave hidden rows
.DisplayPageBreaks = False
.UsedRange.Copy
Selection.PasteSpecial Paste:=xlPasteColumnWidth
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Range("b1:b4").ClearContents
Range("A1:A4").Select
ActiveCell.FormulaR1C1 = "=IFERROR(VLOOKUP(R[7]C,'Team 1'!C[3]:C[5],3,FALSE),"""")"
Range("A8:B8").Select
With Selection.Font
.Name = "Shaw"
.Size = 20
.Bold = True
End With
Dim strSheetName As String
'Worksheet.Cells.Column.Width = 25
'Worksheet.Rows("5:8").RowHeight = 25
With Cells
.ColumnWidth = 25
End With
With Columns("A:A")
.ColumnWidth = 50
End With
With Columns("b:B")
.ColumnWidth = 13
End With
The names start at A8 and the filter usually works to display a single name in a8, copy all the contents, create the page, move on to the next name, only display that one etc etc.
This works 90% of the time. However, some names just don't seem to work with this method and I have been racking my mind to figure out a pattern but I can't. For example - if the list includes "Terry Woo" then all of the entries on the list have terry woo in a8 and then the subsequent name in a9. If I change it to "Terry Wooo" then it works find and only a single row shows up when filtered. Even when I manually filter the row and select only 1 entry to be displayed it displays that entry & Terry Woo.
Any thoughts on this - I've tried about everything I can to figure it out to no avail.
Thanks
Bookmarks