Formato numero en txtbox en excel

Tengo un formulario en excel y un txtbox donde introduzco el precio.

Le he puesto este código y me aparece en el formulario el formato que yo quiero pero cuando me lo vuelca a la tabla me sale en mensaje de que es texto y no número por lo que no puedo hacer cálculos. Si lo convierto a número cuando voy a consultar el registro en el formulario me ha quitado el formato que le había dado.
La idea es que haya el mismo formato en el formulario que en el tabla y que me permita que sea número con símbolo

Private Sub TextBox37_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Me.TextBox37 = Format(Me.TextBox37, "#,##.00 €")
End Sub
Private Sub TextBox7_Change()
Dim codigo As Integer
codigo = TextBox7.Value
Me.TextBox37 = Format(Application.WorksheetFunction.VLookup(codigo, Sheets("BD").Range("A:Ak"), 10, 0, "#,##.00 €"))

de euros para poder sumar

Respuesta
1

Puedes poner el código completo.

No veo el código que hace esto:

Pero cuando me lo vuelca a la tabla

Private Sub MODIFICAR_Click()
Dim fila As Object
Dim linea As Integer
valor_buscado = Me.TextBox7
Set fila = Sheets("BD").Range("A:A").Find(valor_buscado, lookat:=xlWhole)
linea = fila.Row
Range("B" & linea).Value = Me.TextBox1.Value
Range("C" & linea).Value = Me.TextBox2.Value
Range("D" & linea).Value = Me.TextBox5.Value
Range("E" & linea).Value = Me.TextBox4.Value
Range("O" & linea).Value = Format(Me.TextBox37.Value, "#,##.00 €")
End Sub
Private Sub TextBox37_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Me.TextBox37 = Format(Me.TextBox37, "#,##.00 €")
End Sub
Private Sub TextBox7_Change()
Dim codigo As Integer
codigo = TextBox7.Value
Me.TextBox1 = Application.WorksheetFunction.VLookup(codigo, Sheets("BD").Range("A:Ak"), 2, 0)
Me.TextBox2 = Application.WorksheetFunction.VLookup(codigo, Sheets("BD").Range("A:Ak"), 3, 0)
Me.TextBox5 = Application.WorksheetFunction.VLookup(codigo, Sheets("BD").Range("A:Ak"), 4, 0)
Me.TextBox4 = Application.WorksheetFunction.VLookup(codigo, Sheets("BD").Range("A:Ak"), 5, 0)
Me.TextBox37 = Format(Application.WorksheetFunction.VLookup(codigo, Sheets("BD").Range("A:Ak"), 10, 0, "#,##.00 €"))
End Sub
Private Sub txtbuscar_Change()
    NumeroDatos = Hoja4.Range("B" & Rows.Count).End(xlUp).Row
    Me.lista = Clear
    Me.lista.RowSource = Clear
    y = 0
    For fila = 4 To NumeroDatos
        descrip = Hoja4.Cells(fila, 3).Value
            If UCase(descrip) Like "*" & UCase(Me.txtbuscar.Value) & "*" Then
            Me.lista.AddItem
            Me.lista.List(y, 0) = Hoja4.Cells(fila, 1)
            Me.lista.List(y, 1) = Hoja4.Cells(fila, 2)
            Me.lista.List(y, 2) = Hoja4.Cells(fila, 3)
             Me.lista.List(y, 3) = Hoja4.Cells(fila, 16)
            y = y + 1
            End If
    Next
End Sub

aquí te lo mando

gracias

Prueba lo siguiente:

Private Sub MODIFICAR_Click()
  Dim f As Range
  With Sheets("BD")
    Set f = .Range("A:A").Find(Me.TextBox7, lookat:=xlWhole)
    If Not f Is Nothing Then
      .Range("B" & f.Row).Value = Me.TextBox1.Value
      .Range("C" & f.Row).Value = Me.TextBox2.Value
      .Range("D" & f.Row).Value = Me.TextBox5.Value
      .Range("E" & f.Row).Value = Me.TextBox4.Value
      .Range("O" & f.Row).Value = Me.TextBox37.Value
      .Range("O" & f.Row).NumberFormat = "#,##.00 €"
    Else
      MsgBox "No existe el dato"
    End If
  End With
End Sub
'
Private Sub TextBox37_Exit(ByVal Cancel As MSForms.ReturnBoolean)
  Me.TextBox37 = Format(Me.TextBox37, "#,##.00 €")
End Sub
'
Private Sub TextBox7_Change()
  Dim f As Range
  With Sheets("BD")
    Set f = .Range("A:A").Find(Me.TextBox7, lookat:=xlWhole)
    If Not f Is Nothing Then
      Me.TextBox1 = .Range("B" & f.Row)
      Me.TextBox2 = .Range("C" & f.Row)
      Me.TextBox5 = .Range("D" & f.Row)
      Me.TextBox4 = .Range("E" & f.Row)
      Me.TextBox37 = Format(.Range("O" & f.Row), "#,##.00 €")
    End If
  End With
End Sub

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas