Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.il.hebrew.vb,microsoft.public.vb.syntax
external usenet poster
 
Posts: 493
Default Formatting a cell in Excel, using pure VB code

This is one place where the Macro Recorder could have helped you.
When I recorded a macro setting a cell to Text format:

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 10/02/2003 by J.E. McGimpsey
'

'
Selection.NumberFormat = "@"
End Sub


In article ,
"Jean Claude" wrote:

Hi all,

I have a problem with excel cell formatting.
One of the columns should contain phone numbers (a number that starts with
zero ... sometimes)
The VB program puts a phone number lets say - "03555555"
When I open the file from Excel - I see the number without the zero.
I saw that the format of the cell is "General" however I think I should set
the format of the cell to "Text"
I tried several code lines but none helped
Like:
xlsSheet.Cells(1 + I, 3).NumberFormat="Text" - This did not work
xlsSheet.Cells(1 + I, 3)=Chr$(34) & sPhoneNumber & Chr$(34) - With this ,
the cells contained ""
xlsSheet.Cells(1 + I, 3).NumberFormat="00000000" - In this case, when I put
numbers shorter than the number of 0 , example - "031234", the cell
contained "00031234"


Please someone show me the right way ...

Thank you
Frustrated Guy


  #2   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.il.hebrew.vb,microsoft.public.vb.syntax
external usenet poster
 
Posts: 179
Default Formatting a cell in Excel, using pure VB code

Jean Claude

xlsSheet.Cells(1+I,3).NumberFormat = "@"

will format as text.

xlsSheet.Cells(1+I,3).Value = "'" & sPhoneNumber

will enter as a text string regardless of the formatting. That is
doublequote singlequote doublequote.

--
Dick Kusleika
MVP - Excel
www.dicks-clicks.com
Post all replies to the newsgroup.

"Jean Claude" wrote in message
...
Hi all,

I have a problem with excel cell formatting.
One of the columns should contain phone numbers (a number that starts with
zero ... sometimes)
The VB program puts a phone number lets say - "03555555"
When I open the file from Excel - I see the number without the zero.
I saw that the format of the cell is "General" however I think I should

set
the format of the cell to "Text"
I tried several code lines but none helped
Like:
xlsSheet.Cells(1 + I, 3).NumberFormat="Text" - This did not work
xlsSheet.Cells(1 + I, 3)=Chr$(34) & sPhoneNumber & Chr$(34) - With this ,
the cells contained ""
xlsSheet.Cells(1 + I, 3).NumberFormat="00000000" - In this case, when I

put
numbers shorter than the number of 0 , example - "031234", the cell
contained "00031234"


Please someone show me the right way ...

Thank you
Frustrated Guy




  #3   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.il.hebrew.vb,microsoft.public.vb.syntax
external usenet poster
 
Posts: 27,285
Default Formatting a cell in Excel, using pure VB code

Another option

Dim sVal as String
sVal = "03555555"
xlsSheet.Cells(1 + I,3).Value = "'" & sVal

preceding the number with a single quote will cause it to be treated as a
string.

--
Regards,
Tom Ogilvy


"Jean Claude" wrote in message
...
Hi all,

I have a problem with excel cell formatting.
One of the columns should contain phone numbers (a number that starts with
zero ... sometimes)
The VB program puts a phone number lets say - "03555555"
When I open the file from Excel - I see the number without the zero.
I saw that the format of the cell is "General" however I think I should

set
the format of the cell to "Text"
I tried several code lines but none helped
Like:
xlsSheet.Cells(1 + I, 3).NumberFormat="Text" - This did not work
xlsSheet.Cells(1 + I, 3)=Chr$(34) & sPhoneNumber & Chr$(34) - With this ,
the cells contained ""
xlsSheet.Cells(1 + I, 3).NumberFormat="00000000" - In this case, when I

put
numbers shorter than the number of 0 , example - "031234", the cell
contained "00031234"


Please someone show me the right way ...

Thank you
Frustrated Guy




  #4   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.il.hebrew.vb,microsoft.public.vb.syntax
external usenet poster
 
Posts: 5
Default Formatting a cell in Excel, using pure VB code

Hi all,

I have a problem with excel cell formatting.
One of the columns should contain phone numbers (a number that starts with
zero ... sometimes)
The VB program puts a phone number lets say - "03555555"
When I open the file from Excel - I see the number without the zero.
I saw that the format of the cell is "General" however I think I should set
the format of the cell to "Text"
I tried several code lines but none helped
Like:
xlsSheet.Cells(1 + I, 3).NumberFormat="Text" - This did not work
xlsSheet.Cells(1 + I, 3)=Chr$(34) & sPhoneNumber & Chr$(34) - With this ,
the cells contained ""
xlsSheet.Cells(1 + I, 3).NumberFormat="00000000" - In this case, when I put
numbers shorter than the number of 0 , example - "031234", the cell
contained "00031234"


Please someone show me the right way ...

Thank you
Frustrated Guy


  #5   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.il.hebrew.vb,microsoft.public.vb.syntax
external usenet poster
 
Posts: 5
Default Formatting a cell in Excel, using pure VB code

Thank you all

I was looking for this :
xlsSheet.Cells(1+I,3).NumberFormat = "@"

Its workinggggggggggggggg
Guy

??"Dick Kusleika" כתב בהודעה
...
Jean Claude

xlsSheet.Cells(1+I,3).NumberFormat = "@"

will format as text.

xlsSheet.Cells(1+I,3).Value = "'" & sPhoneNumber

will enter as a text string regardless of the formatting. That is
doublequote singlequote doublequote.

--
Dick Kusleika
MVP - Excel
www.dicks-clicks.com
Post all replies to the newsgroup.

"Jean Claude" wrote in message
...
Hi all,

I have a problem with excel cell formatting.
One of the columns should contain phone numbers (a number that starts

with
zero ... sometimes)
The VB program puts a phone number lets say - "03555555"
When I open the file from Excel - I see the number without the zero.
I saw that the format of the cell is "General" however I think I should

set
the format of the cell to "Text"
I tried several code lines but none helped
Like:
xlsSheet.Cells(1 + I, 3).NumberFormat="Text" - This did not work
xlsSheet.Cells(1 + I, 3)=Chr$(34) & sPhoneNumber & Chr$(34) - With this

,
the cells contained ""
xlsSheet.Cells(1 + I, 3).NumberFormat="00000000" - In this case, when I

put
numbers shorter than the number of 0 , example - "031234", the cell
contained "00031234"


Please someone show me the right way ...

Thank you
Frustrated Guy






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
split post code (zip code) out of cell that includes full address Concord Excel Discussion (Misc queries) 4 October 15th 09 06:59 PM
Formatting Code for SI Units in Excel cjbarnwell Excel Worksheet Functions 3 January 26th 08 10:14 AM
conditional formatting w/ more than 3 conditionas, color code to a different cell oldbarnes About this forum 0 May 24th 07 01:27 AM
R6025 pure virtual funtion call Jerry Excel Discussion (Misc queries) 0 February 9th 07 08:37 PM
Runtime Error! R6025 -pure virtual function call STINEHART Excel Discussion (Misc queries) 4 December 7th 06 04:06 PM


All times are GMT +1. The time now is 11:24 PM.

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

About Us

"It's about Microsoft Excel"