Number Formatting with string variables

  • Thread starter Thread starter KempensBoerke
  • Start date Start date
K

KempensBoerke

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
 
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
 
Back
Top