Marco to add tabs to WKS with values from column A

JETober

New Member
Joined
Feb 6, 2020
Messages
4
Office Version
  1. 2016
Platform
  1. Windows
I am needing to write a query to add tabs for each unique value in column A (Employer) and the associated data with each row of data. Any help is appreciated!!

For example

EmployerNameAmountDate
ABC techJoe Smith10007/04/23
X autoMary Johnson5007/01/23

I have this written, but am hitting an error:
Sub CreateSheets()
Application.ScreenUpdating = False
Dim rng As Range, RngList As Object, srcWS As Worksheet
Set srcWS = Sheets("Sheet1")
Set RngList = CreateObject("Scripting.Dictionary")
For Each rng In Range("A1", Range("A" & Rows.Count).End(xlUp))
If Not RngList.Exists(rng.Value) Then
RngList.Add rng.Value, Nothing
With srcWS.Cells(1).CurrentRegion
.AutoFilter 4, rng
If Not Evaluate("isref('" & rng.Value & "'!A1)") Then
Sheets.Add(After:=Sheets(Sheets.Count)).Name = rng
srcWS.AutoFilter.Range.Copy Cells(1, 1)
End If
End With
End If
Next rng
srcWS.Range("A1").AutoFilter
Application.ScreenUpdating = True
End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
This is the culprit.

Sheets.Add(After:=Sheets(Sheets.Count)).Name = rng
 
Upvote 0
Try this:
VBA Code:
With Sheets.Add(ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count))
        .Name = rng
End With
 
Upvote 0
Try this:
VBA Code:
With Sheets.Add(ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count))
        .Name = rng
End With
You also may need to use .Name = rng.Value since you dimensioned rng as Range and Name looks for String, so
VBA Code:
With Sheets.Add(ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count))
        .Name = rng.Value
End With
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,318
Members
452,634
Latest member
cpostell

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top