Hi All,
I have some simple code for formatting a few ranges in Excel (data that was exported from Access). I have just started on this project and am learning lots... I realize that I should use a WITH ... END WITH statement for the following code, but for now, the important problem is that I get the above mentionned error when the code gets to the Third line (ActiveCell.EntireRow.Insert)...
Strange thing is that it does not occur every time; it also leaves on instance of Excel open at the end of the process (loops through a number of Workbooks, creates 9 worksheets in each, saves data, and closes all files).
Any other suggestions on ways to simplify this, improve it, or make it more robust is also appreciated...
Thanks,
Tyler
objSheet.Columns.AutoFit
objSheet.Cells(1, 1).Select
ActiveCell.EntireRow.Insert
objSheet.range(objSheet.Cells(1, 2), objSheet.Cells(1, 11)).Name = "quarterHeader"
objSheet.range("quarterHeader").Value = Array("1 Quarter", "2 Quarter", "3 Quarter", "4 Quarter", "2003", "1 Quarter", "2 Quarter", "3 Quarter", "4 Quarter", "2003")
objSheet.range("quarterHeader").Cells.BorderAround Weight:=xlMedium
objSheet.range("quarterHeader").BorderAround Weight:=xlMedium
objSheet.range("quarterHeader").HorizontalAlignment = xlCenter
objSheet.Cells(1, 1).Select
ActiveCell.EntireRow.Insert
objSheet.range(objSheet.Cells(1, 2), objSheet.Cells(1, 6)).Name = "Import"
objSheet.range("Import").Value = "Import"
range("Import", Cells(1, 6)).Merge
objSheet.range("Import").BorderAround Weight:=xlMedium
objSheet.range("Import").HorizontalAlignment = xlCenter
objSheet.range(objSheet.Cells(1, 7), objSheet.Cells(1, 11)).Name = "Export"
objSheet.range("Export").Value = "Export"
range("Export", Cells(1, 11)).Merge
objSheet.range("Export").BorderAround Weight:=xlMedium
objSheet.range("Export").HorizontalAlignment = xlCenter
objSheet.Cells(1, 1).Select
objSheet.range(objSheet.Cells(1, 1), objSheet.Cells(2, 1)).Name = "Participant"
range("Participant", Cells(2, 1)).Merge
objSheet.range("Participant").Value = "Participant"
objSheet.range("Participant").BorderAround Weight:=xlMedium
objSheet.Cells(1, 1).Select
ActiveCell.EntireRow.Insert
objSheet.range(objSheet.Cells(1, 1), objSheet.Cells(1, 11)).Name = "Subtitle"
range("Subtitle", Cells(1, 11)).Merge
objSheet.range("Subtitle").Value = "By Quarters & Annual"
objSheet.range("Subtitle").BorderAround Weight:=xlMedium
objSheet.range("Subtitle").HorizontalAlignment = xlCenter
objSheet.Cells(1, 1).Select
ActiveCell.EntireRow.Insert
objSheet.range(objSheet.Cells(1, 1), objSheet.Cells(1, 11)).Name = "Title"
range("Title", Cells(1, 11)).Merge
objSheet.range("Title").Value = "Table 4: Statistics by KPC (" & strCountryID & ") in " & strYear & ""
objSheet.range("Title").BorderAround Weight:=xlMedium
objSheet.range("Title").HorizontalAlignment = xlCenter
objSheet.range("Title").Font.Name = "Arial"
objSheet.range("Title").Font.Size = 10
objSheet.range("Title").Font.Bold = True
I have some simple code for formatting a few ranges in Excel (data that was exported from Access). I have just started on this project and am learning lots... I realize that I should use a WITH ... END WITH statement for the following code, but for now, the important problem is that I get the above mentionned error when the code gets to the Third line (ActiveCell.EntireRow.Insert)...
Strange thing is that it does not occur every time; it also leaves on instance of Excel open at the end of the process (loops through a number of Workbooks, creates 9 worksheets in each, saves data, and closes all files).
Any other suggestions on ways to simplify this, improve it, or make it more robust is also appreciated...
Thanks,
Tyler
objSheet.Columns.AutoFit
objSheet.Cells(1, 1).Select
ActiveCell.EntireRow.Insert
objSheet.range(objSheet.Cells(1, 2), objSheet.Cells(1, 11)).Name = "quarterHeader"
objSheet.range("quarterHeader").Value = Array("1 Quarter", "2 Quarter", "3 Quarter", "4 Quarter", "2003", "1 Quarter", "2 Quarter", "3 Quarter", "4 Quarter", "2003")
objSheet.range("quarterHeader").Cells.BorderAround Weight:=xlMedium
objSheet.range("quarterHeader").BorderAround Weight:=xlMedium
objSheet.range("quarterHeader").HorizontalAlignment = xlCenter
objSheet.Cells(1, 1).Select
ActiveCell.EntireRow.Insert
objSheet.range(objSheet.Cells(1, 2), objSheet.Cells(1, 6)).Name = "Import"
objSheet.range("Import").Value = "Import"
range("Import", Cells(1, 6)).Merge
objSheet.range("Import").BorderAround Weight:=xlMedium
objSheet.range("Import").HorizontalAlignment = xlCenter
objSheet.range(objSheet.Cells(1, 7), objSheet.Cells(1, 11)).Name = "Export"
objSheet.range("Export").Value = "Export"
range("Export", Cells(1, 11)).Merge
objSheet.range("Export").BorderAround Weight:=xlMedium
objSheet.range("Export").HorizontalAlignment = xlCenter
objSheet.Cells(1, 1).Select
objSheet.range(objSheet.Cells(1, 1), objSheet.Cells(2, 1)).Name = "Participant"
range("Participant", Cells(2, 1)).Merge
objSheet.range("Participant").Value = "Participant"
objSheet.range("Participant").BorderAround Weight:=xlMedium
objSheet.Cells(1, 1).Select
ActiveCell.EntireRow.Insert
objSheet.range(objSheet.Cells(1, 1), objSheet.Cells(1, 11)).Name = "Subtitle"
range("Subtitle", Cells(1, 11)).Merge
objSheet.range("Subtitle").Value = "By Quarters & Annual"
objSheet.range("Subtitle").BorderAround Weight:=xlMedium
objSheet.range("Subtitle").HorizontalAlignment = xlCenter
objSheet.Cells(1, 1).Select
ActiveCell.EntireRow.Insert
objSheet.range(objSheet.Cells(1, 1), objSheet.Cells(1, 11)).Name = "Title"
range("Title", Cells(1, 11)).Merge
objSheet.range("Title").Value = "Table 4: Statistics by KPC (" & strCountryID & ") in " & strYear & ""
objSheet.range("Title").BorderAround Weight:=xlMedium
objSheet.range("Title").HorizontalAlignment = xlCenter
objSheet.range("Title").Font.Name = "Arial"
objSheet.range("Title").Font.Size = 10
objSheet.range("Title").Font.Bold = True