troubleshooting Question

Modify open spreadsheet column if found in Access VBA

Avatar of atljarman
atljarman asked on
Microsoft AccessMicrosoft ExcelVB Script
4 Comments1 Solution618 ViewsLast Modified:
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"
End If

I was trying code like If firstcol > 0, but i still had the same error:
91-Object variable or With block variable not set
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros