Seite 1 von 1

Convert cell value to currency via code in Basic

Verfasst: Di 6. Apr 2021, 15:19
von TorbenIT
Hello, this code works just fine - I just need to convert my interger number to a currency, but I think it doesn't work like that:

My current Solution at the end of the code snippet is: dest.NumberFormat = "€#,##0.00"

Code: Alles auswählen

	Dim objDatei as Object
	Dim objBlaetter As Object
	Dim objBlatt As Object
	Dim inputC As Object
	Dim dest As Object

	objDatei = ThisComponent
	objBlatt = objDatei.Sheets(0)
	inputC = objBlatt.getCellByPosition(1, 6)
		
		row = 3
		column = 18
	
		dest = objBlatt.getCellByPosition(row, column)
	
		Do While dest.Value <> 0
		
			column = column + 1
			dest = objBlatt.getCellByPosition(row, column)
		
		Loop
	
		dest = objBlatt.getCellByPosition(row, column)
		
		dest.NumberFormat = "€#,##0.00"
		
		dest.Value = inputC.value
		objBlatt.Columns(0).OptimalWidth = True


Re: Convert cell value to currency via code in Basic

Verfasst: Di 6. Apr 2021, 15:58
von TorbenIT
Solution:

Code: Alles auswählen

		CCur(dest.Value)
		CCur(inputC.Value)

Re: Convert cell value to currency via code in Basic

Verfasst: Di 6. Apr 2021, 16:19
von mikele
Hello,
a cell content is either a value, a string or a formula. So what do you mean with convert a value into a currency? I think it's only the format of the cell. CCur() doesn't change this format.
By the way: I'm confused about the language - english or deutsch?