Consulting

Results 1 to 2 of 2

Thread: VBA Help, Getting error: 'That name is already taken. Try a different one'

  1. #1

    VBA Help, Getting error: 'That name is already taken. Try a different one'

    I'm trying to run a macro and I'm getting an error on the top line of this snippet:

    Sheets.Add.Name = "DigikeyRateVariances"
    Set DKData = ActiveSheet
    myRow = 4
    myCol = 4
    Do Until CADsheet.Cells(2, myCol) = ""
    DKData.Cells(myRow, 1) = CADsheet.Cells(2, myCol)
    myCol = myCol + 1
    myRow = myRow + 1

    The error reads 'That name is already taken. Try a different one' I've tried changing the name of the sheet above in quotation marks but I still get the error, nowhere else in my macro is this sheet referenced which is why I'm confused as to why it would try to create 2 sheets, can anyone help please?

  2. #2
    Moderator VBAX Wizard SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,189
    Location
    There is already sheet named "DigikeyRateVariances" when you run the sub.
    For Each Sht In Sheets
    If Sht.Name = "DigikeyRateVariances" Then ShtExists = True
    Next
    
    If Not ShtExists Then Sheets.Add.Name = "DigikeyRateVariances"
    
    Set DKData  Sheets("DigikeyRateVariances")
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •