Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 12th, 2004, 03:11 PM
Authorized User
 
Join Date: Jun 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default How To Force Column To Text

Hi.

I have a column in an Excel 2002 spreadsheet that will contain a 2 character code e.g. "AB" or "09" or nothing. The problem is that the first row of the column has nothing (which is ok), the second has "9" and the third is ok at "AB". I want the "9" to be "09".

The columns are populated programmatically. I tried to set the NumberFormat Property to "Text" but that didn't work. How do I make sure that the column will have two characters and not drop any leading zeros from a string?

TIA.

Rita
 
Old August 12th, 2004, 04:58 PM
Authorized User
 
Join Date: Jun 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I preceded my column with a tick (single quote) and that worked - I'm now getting "09" in my column.

The problem now is that when I open up the spreadsheet, there's a warning message for that cell telling me that a number is stored as text.

How can I programmatically suppress any error/warning messages.

TIA.

Rita
 
Old August 13th, 2004, 12:25 PM
Authorized User
 
Join Date: Aug 2004
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try selecting he column and using Data/Text to columns/finish

-----------------------
Regards BrianB
Most problems occur from starting at the wrong place.
Use a cup of coffee to make Windows run faster.
It is easy until you know how.
 
Old August 13th, 2004, 12:45 PM
Authorized User
 
Join Date: Jun 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Brian.

Thanks for your response but I don't understand what you're getting at.

Rita
 
Old August 13th, 2004, 01:05 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 150
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try this one for the column:

    Application.ErrorCheckingOptions.NumberAsText = False

I got the code with the macroeditor, changing the errorcontrol settings of Excel. Check it out!
 
Old August 13th, 2004, 01:11 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 150
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Seem as if it only works for the application as a whole. Can't be set for a single column.
 
Old August 13th, 2004, 01:18 PM
Authorized User
 
Join Date: Jun 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Birger. That's what I was looking for.
 
Old August 13th, 2004, 03:10 PM
Authorized User
 
Join Date: Jun 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I used "Application.ErrorCheckingOptions.BackgroundChecki ng = False" and that stopped the warning messages I was getting. The only problem is as you said, it's for the whole spreadsheet.
 
Old August 13th, 2004, 03:14 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 150
Thanks: 0
Thanked 0 Times in 0 Posts
Default

True, however, you should be able to define any columns you want as numbers so that they'll act as numbers. Does that solve your problem?
 
Old August 13th, 2004, 03:28 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 150
Thanks: 0
Thanked 0 Times in 0 Posts
Default

As far as i can see, my suggestion only affects columns/cells EXPLICITLY defined as text. Cells, which have not been defined as any special format (=standard) still behaves like standard formatting. Likewise, cells formatted as numbers, still acts as numbers.

Are you sure you want/need to disable all errorchecking, which you say you've done? (.BackgroundChecking = False)?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Runtime Column Header Text vinod_yadav1919 BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 1 November 29th, 2008 01:53 AM
To get text of ButtonField column in GridView nitinp ASP.NET 2.0 Professional 11 May 26th, 2007 12:55 PM
XML EXPLICIT with text column stevemeyns SQL Server 2005 1 February 7th, 2007 01:09 PM
how to capture the text in column khautinh C# 0 December 19th, 2003 01:38 PM
Write column heading to text file cat_trio Access VBA 0 November 13th, 2003 02:32 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.