ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Number Formatting with string variables (https://www.excelbanter.com/excel-programming/293681-number-formatting-string-variables.html)

KempensBoerke

Number Formatting with string variables
 
Hi

I want to achieve a number format with a decimal number in the cell
and behind this number you can find the Unit of Measurement of th
product.

For example: I have a double-variable with content: 21.234,23 tha
represents the amount of liters sold of that product and
string-variable with content “L” that represents the Unit o
Measurement of the sold product. Different UOM’s could appear such a
“P” (pieces), “L” (liters) or M2 (square meters).

The two variables together should mean that I sold 21.234 liters of th
product.

When I look at the cell I should see: 21.234 L , but when I click o
the cell it should just appear as a number in order to be able to mak
calculation.

I have tried this in Exel with “Format Cells”, tab “Number”, choic
“Custom” and that works out fine.

But I should achieve the same result by using VBA-code because I hav
thousands of lines to process in that way. I have been trying my as
off with the bracket-things and could find it. :(

Thank you in advance. ;)

Boerke.

p.s. my apologies if my English is miserable

--
Message posted from http://www.ExcelForum.com


Tom Ogilvy

Number Formatting with string variables
 
Sub AABBCC()
Dim strUnits As String
Dim dblVal As Double
Dim cell As Range
Set cell = Range("B9")
strUnits = "L"
dblVal = 21234.23
cell.NumberFormat = "#,###.00" & " " & strUnits
cell.Value = dblVal

End Sub


--
Regards,
Tom Ogilvy



"KempensBoerke " wrote in
message ...
Hi

I want to achieve a number format with a decimal number in the cell,
and behind this number you can find the Unit of Measurement of the
product.

For example: I have a double-variable with content: 21.234,23 that
represents the amount of liters sold of that product and a
string-variable with content "L" that represents the Unit of
Measurement of the sold product. Different UOM's could appear such as
"P" (pieces), "L" (liters) or M2 (square meters).

The two variables together should mean that I sold 21.234 liters of the
product.

When I look at the cell I should see: 21.234 L , but when I click on
the cell it should just appear as a number in order to be able to make
calculation.

I have tried this in Exel with "Format Cells", tab "Number", choice
"Custom" and that works out fine.

But I should achieve the same result by using VBA-code because I have
thousands of lines to process in that way. I have been trying my ass
off with the bracket-things and could find it. :(

Thank you in advance. ;)

Boerke.

p.s. my apologies if my English is miserable.


---
Message posted from http://www.ExcelForum.com/





All times are GMT +1. The time now is 11:29 AM.

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