Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8928333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:24:56+00:00 2026-06-15T08:24:56+00:00

I have written the following code to create worksheet with names same as the

  • 0

I have written the following code to create worksheet with names same as the names in first column of Sheet1
I am getting a TypeError when trying to set the name on the new worksheet but don’t know why. Can someone help?

Sub CreateWorkSheets()
    '
    ' Macro5 Macro
    '
    '
    Dim r As Range
    Set r = Sheets("Sheet1").Columns(1)
    For Each cell In r
        Dim aa As String

        Dim newSheet As Worksheet
        Set newSheet = Sheets.Add(After:=Sheets(Sheets.Count))
        strTemp = cell.Value
        newSheet.Name = strTemp // Error Here
    Next cell
End Sub

I tried the following code as well and that doesn’t work either even though strValue is valid

Sub Test1()

Sheets("Sheet1").Select
Dim x As Integer
' Set numrows = number of rows of data.
NumRows = Range("A2", Range("A2").End(xlDown)).rows.Count
' Select cell a1.
Range("A2").Select

' Establish "For" loop to loop "numrows" number of times.
For x = 1 To NumRows
    Dim newSheet As Worksheet
    Set newSheet = Sheets.Add(After:=Sheets(Sheets.Count))
    Sheets("Sheet1").Range("B1").Value = "A" + Trim(Str(x))
    strValue = "A" + Trim(Str(x))

    newSheet.Name = Str(Sheets("Sheet1").Range(strValue).Value)
Next

End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:24:59+00:00Added an answer on June 15, 2026 at 8:24 am

    Apparently because you set:

    Set r = Sheets("Sheet1").Columns(1)
    

    It set the cell object to column $A:$A instead of $A$1 like you would think. I put this in the immediate window when I ran into the “cell.value” line:

    ?cell.Address
    $A:$A
    

    You should avoid using an entire column to do what you’re trying to do and I would highly recommend you add these keywords to the top of your module:

    Option Explicit
    

    This will check your code a little more thoroughly and help you avoid unwanted errors.

    To fix this, you can get the exact range you need and I recommend you declare every variable so it stays a specific type.

    Something like this:

    Option Explicit
    
    Sub CreateWorkSheets()
        Dim r As Range
        Dim sh As Worksheet
        Dim tempSh As Worksheet
        Dim cell As Range
        Dim strTemp As String
    
        Set sh = Sheets("Sheet1")
        Set r = sh.Range(sh.Cells(1, 1), sh.Cells(sh.Rows.Count, 1).End(xlUp))
    
        For Each cell In r
            Set tempSh = Sheets.Add(After:=Sheets(Sheets.Count))
            strTemp = cell.Value
            tempSh.Name = strTemp '// no more error
        Next cell
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying my hands on WPF MVVM. I have written following code in
I have written the following code: <h1>Add new book</h1> <%= form_tag :action => 'create'
I have the following code written in delphi2010: TCPClient := TidTcpClient.Create; TCPClient.Host := '192.168.12.131';
I have written the following code and getting the below error, I believe its
I have written the following code to set the cursor of a Gtk::Window from
I am trying to create categorical variables in sas. I have written the following
I have written following code to attach gesture recogniser to multiple imageviews. [imageview1 setUserInteractionEnabled:YES];
i have written the following code class Program { static void Main(string[] args) {
I have written the following code, CrystalDecisions.CrystalReports.Engine.ReportDocument report = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); report.Load(@C:\Users\XXX\Desktop\Backup1\Project\ReportsFolder\ReportSalesInvoice.rpt); Report works
I have written a following code to get just the file name without extension

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.