I have a macro which will insert a new column flagging particular cells.
I want it to then create two tabs based on the values.
My macro is giving me an error 1004 invalid name
for sheet or chart
My code is
Sub Groups()
Columns("L:L").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("L2").Select
Range("L2:L" & Cells(Rows.Count, "A").End(xlUp).Row).Formula = "=IF(OR(RC[-1]=27594,RC[-1]=27601),""Flag"",""Groups Excluding Flag"")"
Range("L1").Select
ActiveCell.FormulaR1C1 = "Test"
Columns("L:L").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Dim c As Range
Dim rng As Range
Dim LR As Long
LR = Cells(Rows.Count, "A").End(xlUp).Row
Set rng = Range("A1:Q" & LR)
Range("L2:L" & LR).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("AM1"), _
Unique:=True
Columns("L:L").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
For Each c In Range([AM2], Cells(Rows.Count, "AM").End(xlUp))
With rng
.AutoFilter
.AutoFilter Field:=5, Criteria1:=c.Value
.SpecialCells(xlCellTypeVisible).Copy
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = c.Value
ActiveSheet.Paste
End With
Next c
End Sub
c
when it errors? Presumably it is not a valid name for a sheet. – SJR Sep 20 '17 at 12:01