I have loaded data from a query into an excel workbook with multiple sheets. The load worked fine. Then I reuse a table with the sheet names to try and access the sheets to hide unused rows. The code errors out on the "Hidden" line of code. I do not close Excel before I run this loop so I did not use another Open Workbook command. Here is my code that I am using to determine if I have a group name in Row 1 Column 1 which is a merged cell with columns 2 and 3 and an employee name in Row 2 Column 3, Sname is set to the first column from a table query. I complete the first pass with entering names onto the sheet, then do a MoveFirst to start at the beginning of the table for loop #2.
Code:
If (ExcelSheet.Sheets(SName).Cells(Counter, 3).Value2 = "0" And _
ExcelSheet.Sheets(SName).Cells(LCounter, 1).Value2 = "0") Or _
(ExcelSheet.Sheets(SName).Cells(Counter, 3).Value2 = " " And _
ExcelSheet.Sheets(SName).Cells(LCounter, 1).Value2 = " ") Or _
(ExcelSheet.Sheets(SName).Cells(Counter, 3).Value2 = "" And _
ExcelSheet.Sheets(SName).Cells(LastCounter, 1).Value2 = "") Then
ExcelSheet.Sheets(SName).Rows(Counter).Select
[b] ExcelSheet.Sheets(SName).EntireRow.Hidden = True [/b]
End If