PDA

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



natonstan
03-02-2017, 04:27 PM
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?

SamT
03-02-2017, 08:22 PM
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")