No recarga el formulario las cantidades con división de miles y decimales (centavos)

Por tu valioso apoyo, tengo esta macro que no me carga al formulario las cantidades con la coma de miles y decimales, El ejemplo es: seleccionar Obra4, y una de los conceptos del 1111 a 1116, clic en “Buscar”. Aquí por no tener centavos la recarga de cantidades la hace bien. Pero al seleccionar los conceptos del 2101 al 2210, que si contienen decimales, no las recarga correctamente. Podrías ayudarme a solucionar este código… Agradezco tus atenciones… y Muchas gracias. (Si necesitas el Archivo te lo envío).

Private Sub CommandButton6_Click() 'ESTE FUNCIONA COMO EL cMMbTON, ES EL BUSCADOR

    Application.ScreenUpdating = False

    For Each h In Sheets

        n = h.Name

        If UCase(h.Name) = UCase(ComboBox1) Then

            existe = True

            Exit For

        End If

    Next

    If existe = False Then

        MsgBox "La hoja seleccionada no existe", vbCritical, "SELCCIONAR OBRA"

        Exit Sub

        ComboBox1.SetFocus

    End If

'IDENTIFICA DATOS GENERALES DE LA OBRA SELECCIONADA

    Set h1 = Sheets(ComboBox1.Value)

    TextBox1 = h1.Range("D3") ' OBRA

    TextBox2 = h1.Range("D4") ' UBICACIÓN, LOCALIZACION

    TextBox3 = h1.Range("D5") ' MUNICIPIO

'xxxxxxxxxx

 'Por.Dante Amor

 ' BUSCA LA PARTIDA O CONCEPTO SELECCIONADA EN CbBx3

     Set b = h1.Range("B:C").Find(What:=ComboBox2, lookat:=xlWhole, LookIn:=xlValues)

       If b Is Nothing Then

          MsgBox "El dato no fue encontrado.", vbOKOnly + vbInformation, "AVISO"

          ComboBox1 = ""

          ComboBox1.SetFocus

       Exit Sub

    Else

    Set b = h1.Range("B:C").Find(What:=ComboBox2, lookat:=xlWhole, LookIn:=xlValues)

    TextBox7 = h1.Range("C" & b.Row) ' Esta línea busca la opción seleccionada (Núm.) que se                                                                    ‘encuentra en CbBx2

    TextBox11 = h1.Range("C" & b.Row)

'xxxxx

        With TextBox1

    TextBox1 = h1.Range("G" & b.Row)  'Col. G Pyto. De gasto

             .Value = Format(.Value, " ##0.00") '1

        End With

'xxxxxx

         With TextBox2 'S

    TextBox2 = h1.Range("H" & b.Row) + h1.Range("I" & b.Row) + h1.Range("j" & b.Row) + h1.Range("k" & b.Row) + h1.Range("l" & b.Row) + h1.Range("m" & b.Row)

            .Value = Format(.Value, " ##0.00") '1

         End With

'xxxxxx

    TextBox3 = Val(TextBox1) - Val(TextBox2)

         r = Val(TextBox1) * 0.81

          If Val(TextBox2) > Val(TextBox1) Then MsgBox "Pago" & Chr(13) & "Excedido...?"

         With TextBox3

            .Value = Format(.Value, "$ #,##0.00") '1

         End With

'xxxxxx

TextBox4 = h1.Range("D" & b.Row)

TextBox5 = h1.Range("E" & b.Row)

TextBox6 = h1.Range("F" & b.Row)

         With TextBox6

            .Value = Format(.Value, "$ #,##0.00") '1

         End With

'----------------

  If TextBox3 < 0 Then

        TextBox3.ForeColor = vbRed

    Else

        TextBox3.ForeColor = vbBlack

    End If

   End If

    Application.ScreenUpdating = True

    h1.Protect

    'Sheets("hoja1").Select

End Sub

1 Respuesta

Respuesta
1

Creo que no tengo el último archivo, envíame el archivo y me dices en qué formulario estás trabajando.

No olvides poner tu nombre "Francisco Moreno" en el asunto del correo

Prueba así:

        With TextBox1
            TextBox1 = h1.Range("G" & b.Row)  'Col. G Pyto. de gasto
            .Value = Format(.Value, "#,##0.00")
        End With
'xxxxxx
         With TextBox2 'S
            TextBox2 = h1.Range("H" & b.Row) + h1.Range("I" & b.Row) + h1.Range("j" & b.Row) + h1.Range("k" & b.Row) + h1.Range("l" & b.Row) + h1.Range("m" & b.Row)
            .Value = Format(.Value, "#,##0.00")
         End With

Correcto Dante... ya me pone la coma divisional de miles, pero el resultado de restar el TxBx1 (menos) el TxBx2  ya no lo hace correctamente, podrías apoyarme con este ultimo detalle... muchas gracias 

Quedaría así:

    With TextBox1
        var_text1 = .Value
        TextBox1 = h1.Range("G" & b.Row)  'Col. G Pyto. de gasto
        .Value = Format(.Value, "#,##0.00")
    End With
'xxxxxx
    With TextBox2 'S
        var_text2 = .Value
        TextBox2 = h1.Range("H" & b.Row) + h1.Range("I" & b.Row) + h1.Range("j" & b.Row) + h1.Range("k" & b.Row) + h1.Range("l" & b.Row) + h1.Range("m" & b.Row)
        .Value = Format(.Value, "#,##0.00")
    End With
'xxxxxx
    TextBox3 = Val(var_text1) - Val(var_text2)

Recuerda lo siguiente, si tienes un número en un textbox, ese número es un texto, lo que tienes que hacer es pasarlo a número con esto val(textbox1), pero si en el textbox le pones formato, es probable que ese texto ya no lo puedas convertir a número.

Si no vas a ocupar los textbox para efectos de presentación, te recomiendo que no les cambies el formato, para que no tengas tantas dificultades en lo sucesivo.

Si no requieres más información, podrías valorar la respuesta.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas