Hi, I have a workbook in which I need to move and rename sheets to a specific location.
I have a table of current worksheet names, names for them to be re-named to, and the location of the sheet with respect to other sheets in the workbook. Here is the code:
In it's current form, I get a runtime error 13 - type mismatch at the "Sheets(c).Move before:=Sheets(Loc)" line. This is true whether I define 'Loc' as an integer, double, single, variant. I profess to know little about defining variables.
'Loc' is the sheet position number within the worksheet.
Before the code breaks, it seems to be picking up 'c' and 'Loc' as I would expect, just not applying 'Loc' as I'd hope.
If I leave 'Loc' without being defined I get a compile error to the effect that function call on the left must return variant or object.
Can anyone help out with this one?
Many thanks.
I have a table of current worksheet names, names for them to be re-named to, and the location of the sheet with respect to other sheets in the workbook. Here is the code:
Code:
Dim ws As Worksheet
Dim Loc As Integer
For Each c In Sheets("admin").Range("set_copyfrom")
Loc = c.Offset(0, 1).Value
Sheets(c).Move before:=Sheets(Loc)
Sheets(c).Name = c.Offset(0, -1).Value
Next c
In it's current form, I get a runtime error 13 - type mismatch at the "Sheets(c).Move before:=Sheets(Loc)" line. This is true whether I define 'Loc' as an integer, double, single, variant. I profess to know little about defining variables.
'Loc' is the sheet position number within the worksheet.
Before the code breaks, it seems to be picking up 'c' and 'Loc' as I would expect, just not applying 'Loc' as I'd hope.
If I leave 'Loc' without being defined I get a compile error to the effect that function call on the left must return variant or object.
Can anyone help out with this one?
Many thanks.