View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
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