Rename a worksheet based on a checkbox list

onche414

New Member
Joined
Aug 7, 2023
Messages
26
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I have an excel file which is a dynamic dashboard. The values changes based on a check box list.
So on the dashboard sheet I have the stores in range B27 to B87. When I hit the box for one of them which is in range A27 to A87, the dahsboard updates itself by gathering datas from the other worksheet.
My objective is to create a code which will save as another excel file the dashboard of each store. I think I managed to do that but what I want to do additionnaly is to rename the name of the worksheet by the name of the store and I keep getting the error "the name is already take". Can you help me on this ?
The line causing the error is : Worksheets(1).Name=Sname

VBA Code:
Sub ExportPDF()


Dim NamePDF As Worksheet
Dim path_PDF As String
Dim Sname As String

path_PDF = "path to folder"
    
Set NamePDF = ActiveWorkbook.Worksheets(1)
           
For i = 27 To 87
Cells(i, 1).Value = "True"
Sname = NamePDF.Cells(i, 2)
Worksheets(1).Name=Sname
 ActiveWorkbook.SaveAs  Filename:=path_PDF & "\" & Sname & ".xlsb", FileFormat:=xlExcel12
  
    Cells(i, 1).Value = "False"
Next i

End Sub


Thank you
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I could be mistaken, but I think this
Sname = NamePDF.Cells(i, 2)
should be this
Sname = Cells(i, 2)
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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