Excel 2013 runtime issue

Associate
Joined
20 Oct 2002
Posts
1,616
Location
North West
I have a macro setup which runs fine in Excel 2010 but generates an immediate subscript out of range error 9 when I run it in Excel 2013.
This is the code.
Code:
ub wibmacro()

Dim wrkbk As Workbook

Dim wksht As Worksheet

Dim wksht2 As Worksheet

Dim i As Long

Dim col As Long

Dim nr As Long

 
Dim wibmacro As Worksheet

Application.ScreenUpdating = True
 

Set wibmacro = ActiveSheet
 

Set wrkbk = Workbooks.Add

Set wksht = wrkbk.Worksheets(1)

Set wksht2 = wrkbk.Worksheets(2)

nr = InputBox("Start Date", "Column No", 3)

 'new line
fn = "TOTAL IB-" & Format(Date, "DD-MMM-YYYY") & ".csv"
ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "\" & fn, FileFormat _
        :=xlCSV, CreateBackup:=False

 

wibmacro.Range(Cells(1, nr), Cells(1, wibmacro.UsedRange.Columns.Count)).Copy wksht.Range("b1")

 

For i = 29 To wibmacro.UsedRange.Rows.Count

 

    wibmacro.Range("a1") = wibmacro.Range("a" & i)

    wibmacro.Rows("6").Calculate

    wibmacro.Range(Cells(6, nr), Cells(6, wibmacro.UsedRange.Columns.Count)).Copy

    wksht.Range("B" & wksht.UsedRange.Rows.Count + 1).PasteSpecial xlPasteValues

    wksht.Range("a" & wksht.UsedRange.Rows.Count) = wibmacro.Range("a" & i)

    
   

   

Next i

wksht.Name = "TOTAL IB"


wksht.Range("A1") = "Item"

  'new line
Workbooks(fn).Save
Workbooks(fn).Close savechanges:=False

 

 

 

End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

End Sub
 
Soldato
Joined
30 Dec 2003
Posts
5,770
Location
London
Have you stepped through it (F8) and work out where the error is?

The 'index' that's out of range is trying to get Worksheets(2) - and if you were to go back and look at the new workbook it creates, you'd notice Excel 2013 only creates a single sheet in new workbooks. Older Excel version always created 3.
 
Back
Top Bottom