Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default format a formula to general (not text)

I am importing a text (.csv) file into excel and formatting it via a Macro.
in one column I have to insert a formula but when I do so, the formula is
showing, i.e. "=TRIM(Z4)". I have tried to format to "general" but it
doesn't work unless I click inside the cell and press enter. How do I apply
the "General" formatting without have to manually click inside the cell? I
want to do it in my macro.

Here is my code:

ActiveCell.Formula = "=TRIM(Z4)"
Selection.NumberFormat = "General"


--
www.bardpv.com
Tempe, Arizona
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default format a formula to general (not text)

The cells are Text formatted.

Simply changing the format will not do the trick as you have found.

Try this construct

With ActiveCell
.Formula = "=TRIM(Z4)"
.NumberFormat = "General"
.Value = .Value 'same as F2Enter
End With


Gord Dibben MS Excel MVP

On Tue, 16 Mar 2010 14:58:01 -0700, Emma Aumack
wrote:

I am importing a text (.csv) file into excel and formatting it via a Macro.
in one column I have to insert a formula but when I do so, the formula is
showing, i.e. "=TRIM(Z4)". I have tried to format to "general" but it
doesn't work unless I click inside the cell and press enter. How do I apply
the "General" formatting without have to manually click inside the cell? I
want to do it in my macro.

Here is my code:

ActiveCell.Formula = "=TRIM(Z4)"
Selection.NumberFormat = "General"


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default format a formula to general (not text)

Try this

With ActiveCell
.NumberFormat = "General"
.Formula = "=TRIM(Z4)"
End With

Your cell is probably preformatted as text, so when you enter the formula,
it remains that way.
--
HTH,

Barb Reinhardt



"Emma Aumack" wrote:

I am importing a text (.csv) file into excel and formatting it via a Macro.
in one column I have to insert a formula but when I do so, the formula is
showing, i.e. "=TRIM(Z4)". I have tried to format to "general" but it
doesn't work unless I click inside the cell and press enter. How do I apply
the "General" formatting without have to manually click inside the cell? I
want to do it in my macro.

Here is my code:

ActiveCell.Formula = "=TRIM(Z4)"
Selection.NumberFormat = "General"


--
www.bardpv.com
Tempe, Arizona

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default format a formula to general (not text)

I think I'd change the order slightly:

With ActiveCell
.NumberFormat = "General"
.Formula = "=TRIM(Z4)"
.Value = .Value 'same as F2Enter
End With


Gord Dibben wrote:

The cells are Text formatted.

Simply changing the format will not do the trick as you have found.

Try this construct

With ActiveCell
.Formula = "=TRIM(Z4)"
.NumberFormat = "General"
.Value = .Value 'same as F2Enter
End With

Gord Dibben MS Excel MVP

On Tue, 16 Mar 2010 14:58:01 -0700, Emma Aumack
wrote:

I am importing a text (.csv) file into excel and formatting it via a Macro.
in one column I have to insert a formula but when I do so, the formula is
showing, i.e. "=TRIM(Z4)". I have tried to format to "general" but it
doesn't work unless I click inside the cell and press enter. How do I apply
the "General" formatting without have to manually click inside the cell? I
want to do it in my macro.

Here is my code:

ActiveCell.Formula = "=TRIM(Z4)"
Selection.NumberFormat = "General"


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 905
Default format a formula to general (not text)


"Gord Dibben" <gorddibbATshawDOTca wrote in message
Try this construct
With ActiveCell
.Formula = "=TRIM(Z4)"
.NumberFormat = "General"


I think it is good to get in the habit of setting .NumberFormat before
setting .Formula.

That avoids problems like the one which Barb presumes is the root cause of
Emma's problem.

Also, consider the difference between:

..Value = "12345678901234567890"
..NumberFormat = "@"

and

..NumberFormat = "@"
..Value = "12345678901234567890"

I suspect the second form is what most people want.

I think the result of the first form is very strange, to say the least.
Assuming the cell format is General and the column width is the default to
begin with, the first form results in a number displayed as General
(TYPE(...) returns 1), but it is left-justified. If the cell is
subsequently re-evaluated (e.g. press F2, then Enter), the result is text
(TYPE(...) returns 2); but the text is the first 15 significant digits
followed by zeros -- exactly what we see in the Formula Bar before
re-evaluating the cell.


.Value = .Value 'same as F2Enter


I don't think so.

The statement above replaces the formula with the result of the formula;
that is, it replaces the formula with a constant value. In contrast,
pressing F2, then Enter would simply re-evaluate the formula. But the
formula will still be left in the cell.


----- original message -----

"Gord Dibben" <gorddibbATshawDOTca wrote in message
...
The cells are Text formatted.

Simply changing the format will not do the trick as you have found.

Try this construct

With ActiveCell
.Formula = "=TRIM(Z4)"
.NumberFormat = "General"
.Value = .Value 'same as F2Enter
End With


Gord Dibben MS Excel MVP

On Tue, 16 Mar 2010 14:58:01 -0700, Emma Aumack
wrote:

I am importing a text (.csv) file into excel and formatting it via a
Macro.
in one column I have to insert a formula but when I do so, the formula is
showing, i.e. "=TRIM(Z4)". I have tried to format to "general" but it
doesn't work unless I click inside the cell and press enter. How do I
apply
the "General" formatting without have to manually click inside the cell?
I
want to do it in my macro.

Here is my code:

ActiveCell.Formula = "=TRIM(Z4)"
Selection.NumberFormat = "General"



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
Vlookup,format general, format text techguy99 New Users to Excel 2 April 10th 09 01:35 AM
Format text to general Gator Excel Discussion (Misc queries) 2 September 9th 08 04:24 PM
Converting general text format to date Sarah (OGI) Excel Discussion (Misc queries) 6 June 20th 08 02:24 PM
Format: General - Text - General iturnrocks Excel Worksheet Functions 3 August 11th 06 04:47 PM
VBA automatically change text format into general format? Nicawette Excel Programming 2 June 13th 06 01:35 PM


All times are GMT +1. The time now is 07:01 AM.

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"