Problem with formating

  • Thread starter Thread starter DG
  • Start date Start date
D

DG

I have an array that contains string values. When I put one of these values
into my spreadsheet it changes to Scientific.

Dim DataRow(12)

DataRow(9)="201E-13" ' for this example
Line = 2 ' for this example

Sheets("Sheet2").Cells(Line,9) = DataRow(9)

The result in Sheet2 I2 = 2.01E-11 and the format is Scientific. I manually
set this column to text before running the macro.

Any help would be great.

DG
 
Seems slightly strange your string is being coerced to a number in a cell
that you say is already formatted as text. What happens if you run this -

s$ = Format(Now, "yyyymmddhhmmss")
With ActiveCell
..NumberFormat = "@"
..Value = s
End With

Regards,
Peter T
 
Thanks Joel but that did not work.

I even tried

Sheets("Sheet2").Cells(Line,9) = Str(DataRow(9))

but got a type mismatch error

Any other ideas?

DG
 
Hi Peter,

I ran your script and it put 20080418100810 in cell A1 with the warning that
I have a number foratted as text in the cell.

DG
 
OK, so what happens if you format your cells the same way before you dump
your string values to the cells.

Regards,
Peter T
 
I found it.

I was manually formating the column to text BEFORE I ran the macro. At the
begining of the macro I have:

With Range("A8:K10000")
.Clear
End With

which removed the format. When I comment this out my macro works. Problem
is that I need that clear. So Can you tell me how to format column I as
text?

DG
 
Got it.

..NumberFormat = "@"

Thanks

DG said:
I found it.

I was manually formating the column to text BEFORE I ran the macro. At
the begining of the macro I have:

With Range("A8:K10000")
.Clear
End With

which removed the format. When I comment this out my macro works.
Problem is that I need that clear. So Can you tell me how to format column
I as text?

DG
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top