Numberformat with VBA using Automation

J

jeanjanssens

Hi there,

I have a procedure in Access that exports data to an Excel worksheet.
Can anyone here help me with the finer side of Excel VBA and its
methods, please?

I have the following code so far:

Public gobjExcel As Excel.Application 'global variable
-------------------------------------------------------
Private Sub cmdExportieren_Click() 'actual procedure

Dim objWS As Excel.Worksheet

gobjExcel.Workbooks.Add
objWS.Range("A2").CopyFromRecordset rstData, 1000 'export
gobjExcel.Range("A1").Select

'code I want must go here

end sub

---------------------------------------------

So what I want in VBA is that I check the cell contents in a specific
range, and when the cell contents has a number in it, it must be a
decimal value with only 1 place after the comma.
Can this be written with an IF loop inside the VBA of Access?

I am grateful for any tips, or if someone can maybe point to a resource
on the web where this is explained.

Kind Regards,
Jean
 
M

Markus Scheible

Hi Jean,
So what I want in VBA is that I check the cell contents in a specific
range, and when the cell contents has a number in it, it must be a
decimal value with only 1 place after the comma.
Can this be written with an IF loop inside the VBA of
Access?


try

For Each cell In Range("whatever")
If IsNumeric(cell.Value) = True Then cell.NumberFormat
= "0.0"
End If
Next cell


Best

Markus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top