ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Problem with formating (https://www.excelbanter.com/excel-programming/409598-problem-formating.html)

DG

Problem with formating
 
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



joel

Problem with formating
 
Dim DataRow as string
Dim DataRow(12) as string


"DG" wrote:

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




Peter T

Problem with formating
 
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

"DG" wrote in message
...
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





DG

Problem with formating
 
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

"Joel" wrote in message
...
Dim DataRow as string
Dim DataRow(12) as string


"DG" wrote:

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






DG

Problem with formating
 
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

"Peter T" <peter_t@discussions wrote in message
...
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

"DG" wrote in message
...
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







Peter T

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

Regards,
Peter T

"DG" wrote in message
...
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

"Peter T" <peter_t@discussions wrote in message
...
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

"DG" wrote in message
...
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









DG

Problem with formating
 
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

"DG" wrote in message
...
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

"Peter T" <peter_t@discussions wrote in message
...
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

"DG" wrote in message
...
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









DG

Problem with formating
 
Got it.

..NumberFormat = "@"

Thanks

"DG" wrote in message
...
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

"DG" wrote in message
...
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

"Peter T" <peter_t@discussions wrote in message
...
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

"DG" wrote in message
...
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












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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com