Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Numberformat for Cells using Automation

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 it 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




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Numberformat for Cells using Automation


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


Dim text As String
Dim pos As Long
text = gobjExcel.Range("A1").Value
If IsNumeric(text) Then
text = Round(text, 1)
gobjExcel.Range("A1").Value = text
End If


Patrick Molloy
Microsoft Excel MVP

"bavjean" wrote:

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 it 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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Numberformat for Cells using Automation

also try

WITH gobjExcel.Range("B1:B1000")
.FormulaR1C1 = "=ROUND(RC[-1],1)"
.Value = .Value
END WITH
WITH gobjExcel.Range("A1:A1000")
.FormulaR1C1 = "=RC[1]"
.Value = .Value
END WITH


it would of course b easier if your recordset hald the data correctly
formatted!

"Patrick Molloy" wrote:


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


Dim text As String
Dim pos As Long
text = gobjExcel.Range("A1").Value
If IsNumeric(text) Then
text = Round(text, 1)
gobjExcel.Range("A1").Value = text
End If


Patrick Molloy
Microsoft Excel MVP

"bavjean" wrote:

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 it 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




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Numberformat for Cells using Automation

Patrick,

Will try both your suggestions at some time.
My recordset comes from a query which I have also tried to format the
numbers with round(), but no luck yet!

Thanks for the tips!

"Patrick Molloy" schrieb:

also try

WITH gobjExcel.Range("B1:B1000")
.FormulaR1C1 = "=ROUND(RC[-1],1)"
.Value = .Value
END WITH
WITH gobjExcel.Range("A1:A1000")
.FormulaR1C1 = "=RC[1]"
.Value = .Value
END WITH


it would of course b easier if your recordset hald the data correctly
formatted!

"Patrick Molloy" wrote:


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


Dim text As String
Dim pos As Long
text = gobjExcel.Range("A1").Value
If IsNumeric(text) Then
text = Round(text, 1)
gobjExcel.Range("A1").Value = text
End If


Patrick Molloy
Microsoft Excel MVP

"bavjean" wrote:

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 it 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




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel automation through .NET Interop: NumberFormat property looks like NumberFormatLocal martin durtschi Excel Programming 4 May 13th 14 07:39 PM
numberformat? Jack Sons Excel Discussion (Misc queries) 3 September 4th 07 03:44 PM
using cells.numberformat maxzsim Excel Worksheet Functions 2 May 6th 05 10:41 AM
Writing Localized Strings In Cells Using Automation VirGin Excel Discussion (Misc queries) 0 March 7th 05 01:04 PM
NumberFormat strings for Excel Cells R. L. Alan Jordan Excel Programming 2 July 26th 03 02:33 AM


All times are GMT +1. The time now is 10:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"