For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic Syntax > April 2005 > Export to Excel and format the cells to be specific data types









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Export to Excel and format the cells to be specific data types
gonkowonko@gmail.com

2005-04-11, 4:03 pm

Hi all

I have searched all over to do this but cannot find it so ....

What i am doing is im creating a custom Excel Spreadsheet from a load
of data i have which is stored into an array. I can write the spread
sheet etc and it all looks good except for one thing i want to force
specific columns to be a number with 2 decimal places as currently
10.00 get put in as 10.

To give u a brief example of my shoddy coding.....

-------------------------------------------------------
Set objXL = New Excel.Application
Set objWB = objXL.Workbooks.Add
Set objWS = objWB.Worksheets(1)


With objWS

.Cells(1, 1) = "TEXT"

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

Any help or advice would be GREAT!!!!!

Cheers

Gaz

Jan Hyde

2005-04-11, 4:03 pm

gonkowonko@gmail.com's wild thoughts were released on 11 Apr
2005 09:02:56 -0700 bearing the following fruit:

>Hi all
>
>I have searched all over to do this but cannot find it so ....
>
>What i am doing is im creating a custom Excel Spreadsheet from a load
>of data i have which is stored into an array. I can write the spread
>sheet etc and it all looks good except for one thing i want to force
>specific columns to be a number with 2 decimal places as currently
>10.00 get put in as 10.
>
>To give u a brief example of my shoddy coding.....
>
>-------------------------------------------------------
> Set objXL = New Excel.Application
> Set objWB = objXL.Workbooks.Add
> Set objWS = objWB.Worksheets(1)
>
>
> With objWS
>
> .Cells(1, 1) = "TEXT"
>
>------------------------------------------------------
>
>Any help or advice would be GREAT!!!!!
>
>Cheers
>


Start recording a macro, format the cells manually. Stop the
macro. Then look at the code it has generated.




Jan Hyde (VB MVP)

--
Untold Wealth: That which does not appear on your income tax return
(Robert Meyers)

[Abolish the TV Licence - http://www.tvlicensing.biz/]

Veign

2005-04-11, 4:03 pm

Something like;
Range("A1").Select
Selection.NumberFormat = "0.00"

If you ever need Excel or Word VBA code just goto the application and use
the Record Macro feature. This will get you pointed in the right
direction..

--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
--
Read. Decide. Sign the petition to Microsoft.
http://classicvb.org/petition/


<gonkowonko@gmail.com> wrote in message
news:1113234890.895736.20930@o13g2000cwo.googlegroups.com...
> Hi all
>
> I have searched all over to do this but cannot find it so ....
>
> What i am doing is im creating a custom Excel Spreadsheet from a load
> of data i have which is stored into an array. I can write the spread
> sheet etc and it all looks good except for one thing i want to force
> specific columns to be a number with 2 decimal places as currently
> 10.00 get put in as 10.
>
> To give u a brief example of my shoddy coding.....
>
> -------------------------------------------------------
> Set objXL = New Excel.Application
> Set objWB = objXL.Workbooks.Add
> Set objWS = objWB.Worksheets(1)
>
>
> With objWS
>
> .Cells(1, 1) = "TEXT"
>
> ------------------------------------------------------
>
> Any help or advice would be GREAT!!!!!
>
> Cheers
>
> Gaz
>



gonkowonko@gmail.com

2005-04-12, 8:58 am

Sorted Thanks guys never thought of doing it that way !!!!

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com