I have a function that creates a spreadsheet from a query object very nicely. The problem is that a few of the columns are not formatted correctly. I've added code to the function so that as the spreadsheet is being created it formats the column correctly. Now if the column in the spreadsheet does not exist, it errors out. I thought I added check code to see if the spreadsheet had a column name of the one I'm trying to format, and it doesn't work. Any thoughts.
'This is where I'm trying to look for the column "Doc2"
myField = "Doc2"
If .Cells.Find(What:=myField, SearchDirection:=xlNext, SearchOrder:=xlByColumns) Is Nothing Then
firstcol = .Cells.Find(What:=myField, SearchDirection:=xlNext, SearchOrder:=xlByColumns).Column
.Range(.Cells(1, firstcol), .Cells(lngMaxRow + 1, firstcol)).NumberFormat = "0"
I was trying code like If firstcol > 0, but i still had the same error:
91-Object variable or With block variable not set