My macro is below. all the bits work independently but put them together and i get errors.
If I dim this line it works perfectly. All I want the macro to do is to create a new sheet prior to filling it with data, any ideas why this is happening as i'm pulling my hair out. (i've not got much to begin with).
Application.Run "'saved macros.xls'!AddSheet"
Sub DoTables9r7c()
Dim i As Long, j As Long, k As Long, r As Range, s As Worksheet
Application.ScreenUpdating = False
Application.Run "'saved macros.xls'!AddSheet"
Set s = Sheets("Update") 'sheet to copy tables to
s.UsedRange.Clear 'start with clean sheet
k = 0
i = 1582 'enter the first row of table to convert
Set r = Cells(i, 1)
While Not IsEmpty(r)
k = k + 1
r.Copy s.Cells(k, 1)
Set r = Range(Cells(i + 1, 2), Cells(i + 1, 2)) 'change 7 to number of columns and 8 to columns + 1
For j = 1 To 1 'this refers to the number of rows
r.Rows(j).Copy s.Cells(k, 17 * (j - 1) + 2) ' change 7 to number of columns
Next j
i = i + 19 'this is the interval between the first row of subsequent tables
Set r = Cells(i, 1)
Wend
Sheets("Update").Select
Columns("B:B").Select
Selection.Insert Shift:=xlToRight
Cells.Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Cells.Replace What:="-", Replacement:="0", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False
Application.Run "'saved macros.xls'!TextToColumnGorJ"
End Sub
Sub AddSheet()
Sheets.Add
Sheets("Sheet2").Select
Sheets("Sheet2").Name = "Update"
Range("A1").Select
End Sub
yours gratefully
giorgio