Textbox formato moneda

hola gente me estoy volviendo loco, je je no puedo hacer que el textbox me pase los datos a la celda con formato moneda.

este es el código:

Private Sub CommandButton1_Click()
Dim CÓDIGO As String
Dim descripción As String
Dim Stock As String
Dim Preciocosto As String
Dim preciofinal As String
Dim ultimafila As Double
descripción = txtdescripcion.Value
Stock = txtStock.Value
Preciocosto = txtPreciocosto.Value
CÓDIGO = cmbcodigo.Value
preciofinal = Txtpreciofinal.Value


Txtpreciofinal = Preciocosto * 1.5


'usar cmb código para sumar stock
dato = cmbcodigo.Value
Set busco = Sheets("PRODUCTOS").Range("A:A").Find(dato, LookIn:=xlValues, lookat:=xlWhole)
If Not busco Is Nothing Then
TextBox1 = CInt(txtStock.Value) + CInt(txtcantidad.Value)
busco.Offset(0, 2) = TextBox1
cmbcodigo = Empty
txtdescripcion = Empty
txtStock = Empty
txtPreciocosto = Empty
txtcantidad = Empty
cmbcodigo.SetFocus
'sino
Else
ultimafila = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.Count
Cells(ultimafila + 1, 1) = CÓDIGO
Cells(ultimafila + 1, 2) = descripción
Cells(ultimafila + 1, 3) = Stock + txtcantidad
Cells(ultimafila + 1, 4) = Preciocosto
Cells(ultimafila + 1, 5) = Txtpreciofinal
'borrar los txtbox
cmbcodigo = Empty
txtdescripcion = Empty
txtStock = Empty
txtPreciocosto = Empty
txtcantidad = Empty
cmbcodigo.SetFocus
End If
' ordenar alfabéticamente de a a z por descripción
Columns("B:B").Select
ActiveWorkbook.Worksheets("PRODUCTOS").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("PRODUCTOS").Sort.SortFields.Add Key:=Range("B2"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("PRODUCTOS").Sort
.SetRange Range("A2:E99999")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub

En otro archivo y otro formulario e usado esto:

Private Sub TextBox3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox3.Value = Format(Val(TextBox3), "$ #,##0.00")

Pero aca precio costo lo pasa bien sin ponerle nada, ahora precio final no hay forma.

desde ya muchas gracias

1 Respuesta

Respuesta
1

Los textbox son siempre texto... de ahí la necesidad de 'convertirlos'. A veces para realizar cálculos, otras para enviar a la hoja.

En tu caso solo necesitas anteponer una de esas funciones al txt:

Cells(ultimafila + 1, 5) = CDbl(Txtpreciofinal) 'asumiendo que tiene centavos.

PD) La celda ya tendrá además el formato adecuado.

gracias quedo bien, te hago otra pregunta

en la parte donde

TextBox1 = CInt(txtStock.Value) + CInt(txtcantidad.Value)

me lo pasa en texto también. Solo cuando sumo sino lo pasa bien.

Gracias

En todos los textbox, al pasarlos a la hoja colocale la función Val o Cdbl... según sea entero o decimal.

Sdos

Elsa

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas