Hi All,
I'm sure this is quite simple but I can't see where I'm going wrong. I'm exporting an Access query to Excel, but formatting the Excel sheet afterwards. Here's the main bit of code - I've numbered the lines so I can explain the problem!
(1)
xlProjectCosts.ActiveSheet.Cells(currentRow, 2).CopyFromRecordset rsMatrix
(2)
currentCol = rsMatrix.Fields.Count + 2
currentRow = currentRow + rsMatrix.RecordCount
(3)
'xlProjectCosts.ActiveSheet.Range(Cells(7, 3), Cells(currentRow, currentCol)).NumberFormat = "$#,##0.00"
I need all the variables in line(3) because the recordset will always have different numbers of columns and rows. I want all of the cells to be formatted as currency. Previously I had specified a range to format using the A1 notation, and then the whole thing ran fine. If I comment out line(3) it still works fine. But when I run it as it is, I get an error in line(1): 1004 Application-defined or object-defined error.
Can anyone throw any light on this?
Thanks in advance!
I'm sure this is quite simple but I can't see where I'm going wrong. I'm exporting an Access query to Excel, but formatting the Excel sheet afterwards. Here's the main bit of code - I've numbered the lines so I can explain the problem!
(1)
xlProjectCosts.ActiveSheet.Cells(currentRow, 2).CopyFromRecordset rsMatrix
(2)
currentCol = rsMatrix.Fields.Count + 2
currentRow = currentRow + rsMatrix.RecordCount
(3)
'xlProjectCosts.ActiveSheet.Range(Cells(7, 3), Cells(currentRow, currentCol)).NumberFormat = "$#,##0.00"
I need all the variables in line(3) because the recordset will always have different numbers of columns and rows. I want all of the cells to be formatted as currency. Previously I had specified a range to format using the A1 notation, and then the whole thing ran fine. If I comment out line(3) it still works fine. But when I run it as it is, I get an error in line(1): 1004 Application-defined or object-defined error.
Can anyone throw any light on this?
Thanks in advance!