Share via

VBA print cell value format

Anonymous
2017-10-31T13:33:00+00:00

Hi,

I am currently working on an excel macro, which should print several text and numerical values into a text file. It works fine, with one small problem. The files I am generating are supposed to be processed in a special FORTRAN based software, which demands all number in dotted format, e.g. 2.0 is ok nad 2 is not ok.

The code I am using for printing is given below:

Print #1, "@"

Print #1, "@     " & Worksheets("List1").Cells(i, 1).Value

Print #1, "@"

Would you be so kind and tell me, how to force the print function to write all numbers in dotted or mathematical format?

Thanks for help

Adam

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2017-10-31T16:17:04+00:00

Use the .Text property of the cell instead of the .Value   -  .Text is the cell-formatted .Value    As long as your cells are properly formatted for the desired output, you are golden.

If you need to use a different format, then use

Format(Cell.Value,"format string")

For example, this will force two decimals

Print #1, "@     " & Format(Worksheets("List1").Cells(i, 1).Value,"0.00")

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

0 additional answers

Sort by: Most helpful