Need to clear contents of an Excel cell that has a value of $0.00 using Microsoft Access VBA!

Please note code below used to send a SQL set of data to Microsoft Excel's object.
I need to be able to add one more step  - if any value in columns AR - AZ comes out to $0.00 (which in reality is =SUM(AI2:AP2) go ahead and do a Clear Contents on that cell so it is blank - I need to do it for that entire range of columns and rows - every row under columns AR - AZ.

What syntax or statement I can add using Access VBA that would allow me to do that?

Thank you sincerely in advance.


 Set xlApp = CreateObject("Excel.Application")
  'Opens Excel TEMPlate always from the C:\ to reduce traffic
  Set xlBook = xlApp.Workbooks.Open(sFile)
  Set xlSheet = xlBook.Worksheets(1)
  xlSheet.Application.Visible = True
  If sRange = "" Then sRange = "A2"
  Set rs = Application.CurrentProject.Application.CurrentDb.OpenRecordset(sSQLExcel)
  With xlSheet
    '.Range("C1").Value = Date
    '.Range("A5").copyfromrecordset rs
    .Range(sRange).copyfromrecordset rs
    '.Name = strSheetName
  End With
On Error GoTo Err_Skip_Columns

  xlSheet.Sheets(1).Columns("AI").TextToColumns DataType:=1
  xlSheet.Sheets(1).Columns("AJ").TextToColumns DataType:=1
  xlSheet.Sheets(1).Columns("AK").TextToColumns DataType:=1
  xlSheet.Sheets(1).Columns("AL").TextToColumns DataType:=1
  xlSheet.Sheets(1).Columns("AM").TextToColumns DataType:=1
  xlSheet.Sheets(1).Columns("AN").TextToColumns DataType:=1
  xlSheet.Sheets(1).Columns("AO").TextToColumns DataType:=1
  xlSheet.Sheets(1).Columns("AP").TextToColumns DataType:=1
  xlSheet.Sheets(1).Columns("AQ").TextToColumns DataType:=1
  xlSheet.Sheets(1).Columns("AR").TextToColumns DataType:=1
  xlSheet.Sheets(1).Columns("AS").TextToColumns DataType:=1
  xlSheet.Sheets(1).Columns("AT").TextToColumns DataType:=1
  xlSheet.Sheets(1).Columns("AU").TextToColumns DataType:=1
  xlSheet.Sheets(1).Columns("AV").TextToColumns DataType:=1
  xlSheet.Sheets(1).Columns("AW").TextToColumns DataType:=1
  xlSheet.Sheets(1).Columns("AX").TextToColumns DataType:=1
  xlSheet.Sheets(1).Columns("AY").TextToColumns DataType:=1
  xlSheet.Sheets(1).Columns("AZ").TextToColumns DataType:=1
  wb.Sheets(1).Range("AI:AZ").NumberFormat = "$#,##0.00"

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


You could try this format

wb.Sheets(1).Range("AR:AZ").NumberFormat = "$#,##0.00;$-#,##0.00;"""""
or clear contents

For Each c In Intersect(wb.Sheets(1).UsedRange, wb.Sheets(1).Range("AR:AZ"))
    If c.Value = 0 Then
    End If


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
stephenlecomptejrAuthor Commented:
When I try :
 wb.Sheets(1).Range("AR:AZ").NumberFormat = "$#,##0.00;$-#,##0.00;"""""

I get a object doesn't support this property or method.

When I try the second one instead:

For Each c in Intersect

I get a sub or function not defined with it highlighting Intersect.  Please note this uses late binding because some may have different version of Microsoft Excel.

pls try

For Each c in xlApp.Intersect
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

stephenlecomptejrAuthor Commented:
Also should c be an integer?
Maybe the format could be

wb.Sheets(1).Range("AR:AZ").NumberFormat = "$#,##0.00;$-#,##0.00;"
c is an Excel range
stephenlecomptejrAuthor Commented:
The first line worked for me.  My problem was I was using xlSheet. versus xlBook. as his code indicates wb for Workbook.
stephenlecomptejrAuthor Commented:
Thanks again Rgonzo1971 - I appreciate it.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.