PDA

View Full Version : Set



next
02-25-2008, 04:22 PM
I'm confused, why is this generating me an error?

Public agesumCWI As Worksheet, agesumCLS As Worksheet
Sub editAgesum()
Sheets.Add.Name = "Licensing"
Sheets("agesum").Name = "Cleanway"

Set agesumCWI = ThisWorkbook.Worksheets("Cleanway")
Set agesumCLS = ThisWorkbook.Worksheets("Licensing")
agesumCWI.Move before:=agesumCLS
End Sub

Error: Out of Range.

Basically what i'm trying to achieve: I have a spreadsheet with 1 tab called "agesum", i'm adding a second tab called "Licensing", renaming "agesum" to "Cleanway" and then i'm assigning it to a var(2 of 'em).
It all works up to first "Set" statement.

Thanks for your help.

Bob Phillips
02-25-2008, 04:29 PM
Works fine for me, even if agesum is protected. Just a thought, is it a shared workbook?

tstav
02-25-2008, 04:40 PM
If your "agesum" Sheet is a Worksheet your code should work fine.

Make sure it is not a Chartsheet.

If it is then the <Sheets("agesum").Name = "Cleanway"> line will work,
but the <Set agesumCWI = ThisWorkbook.Worksheets("Cleanway")> will produce an error. There is no Worksheets("Cleanway") thus the Out of Range message.

next
02-25-2008, 05:16 PM
No, it's a regular Worksheet. Few questions:
a) Does format matter? Mine is in *.dif
b)
There is no Worksheets("Cleanway") thus the Out of Range message. Can it be that the code works to fast? What i mean is what if it renames the tab to slow? Should i maybe pause it (how?)?

P.S. How can i create a tab, name it and set it to be second in 1 line?
can i do that?
Just checking if i can avoid using agesumCWI.Move before:=agesumCLS


Edit:
Just tryied it at home, it's not working, it's generating the same error.

Edit:
Found it. "ThisWorkbook" isn't working for some reason, i replaced it with "Workbooks("agesum.dif")" and it's working just fine now. Is there a reason for ThisWorkbook not to work?