I am trying to use a macro to add a sheet after an specific sheet. Let's say this sheet is named 102014. I want this macro to create a sheet after the 102014 one with the name 112014, but I can't use select or active sheet because it is actually part of a big macro and I switch back and forth between workbooks. Here is what I tried to do, with no success:
dim wbname as string
dim thismonth as string
dim lastmonth as string
thismonth = ThisWorkbook.Worksheets("Sheet2").Cells([address of a cell with the name of the sheet).Value
lastmonth = ThisWorkbook.Worksheets("Sheet2").Cells([address of a cell with the name of the sheet).Value
wbname = ThisWorkbook.Sheets("Sheet2").Cells([address of a cell with the file name here])
Workbooks(wbname).Sheets.Add(After = wbkname.Sheets(lastmonth)).Name = thismonth
The macro simply passes this last line and goes to the other one, no error, no nothing. As you can see, I have a list with the sheet names and file names, and this is where I get the thismonth
, lastmonth
and wbname
variables from.
What am I doing wrong?