ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VB Code + Runtime error 91 (https://www.excelbanter.com/excel-programming/383181-vbulletin-code-runtime-error-91-a.html)

[email protected]

VB Code + Runtime error 91
 
I have been working on this vb code for a while now. The scenario is
that I am taking 1million+ records, filtering them through Access,
then exporting them to Excel. Once they are in excel I am appling
formulas and formats to specific columns. The sheets are spit out one
salesman at a time, formatted, closed, then the next one is spit out,
formatted and closed, and so on.

The very first sheet that comes out works great. However, it will not
continue. I end up with a Runtime Error 91 "Object variable or With
block variable not set". When I press debug "xl.Range(Selection,
Selection.End(xlUp).Offset(1, 0)).Select" is highlighted.

'Column GM%
xl.Range("A65536").End(xlUp).Offset(0, 11).Select
xl.Range(Selection, Selection.End(xlUp).Offset(1, 0)).Select
With xl.Selection.Interior
.Pattern = xlSolid
.ColorIndex = 33
End With
xl.Selection.NumberFormat = "0.0%"
xl.Range("A1").Select

If I take out that one line, everything is fine, except that I do not
get that column filled in with the color, but it does continue to the
next set of formats, stopping at the same spot in this section:

xl.Range("A65536").End(xlUp).Offset(0, 13).Select
xl.Range(Selection, Selection.End(xlUp).Offset(1, 0)).Select
With xl.Selection.Interior
.ColorIndex = 36
.Pattern = xlSolid
End With
xl.Selection.NumberFormat = "0.0%"
xl.Range("A1").Select

Does anyone have any ideas of what I am doing wrong here?

Thank you in advance.



All times are GMT +1. The time now is 05:05 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com