Introducir Números en un Textbox

Tengo varios Textbox donde debo ingresar números (del 0 al 10)en cada uno, lo que ocurre que al sumar cuando sierro el formulario son texto por consecuencia error en la suma.

Encontré la función CDbl pero da error si en algún TextBox no ingreso numero, por que se da que en algunos casos no debo ingresar el numero.

1 Respuesta

Respuesta
1

¿Ya intentaste?, por poner un ejemplo

Textbox1.text=val(textbox1.text), porlo general todo lo que captures en un textbox lo va a pasar a texto por eso hay que convertirlo a numero con val cuando se requiere.

No funciono por tal motivo te paso lo que arme tal vez estoy cometiendo algún error 

Private Sub ComandIngreso_Click()

Dim Cliente As String 'Variable para almacenar valores de cliente

Dim Direccion As String 'Variable para almacenar valores de Direccion

Dim Provincia As String 'Variable para almacenar valores de Provincia

Dim Venta As String 'Variable para almacenar valores de Venta

Dim Cuit As String 'Variable para almacenar valores de Cuit

Dim Cant01 As String 'Variable para almacenar valores de Cantidad01

Dim Cant02 As String 'Variable para almacenar valores de Cantidad02

Dim Cant03 As String 'Variable para almacenar valores de Cantidad03

Dim Cant04 As String 'Variable para almacenar valores de Cantidad04

Dim Cant05 As String 'Variable para almacenar valores de Cantidad05

Dim Cant06 As String 'Variable para almacenar valores de Cantidad06

Dim Cant07 As String 'Variable para almacenar valores de Cantidad07

Dim Cant08 As String 'Variable para almacenar valores de Cantidad08

Dim Cant09 As String 'Variable para almacenar valores de Cantidad09

Dim Cant10 As String 'Variable para almacenar valores de Cantidad10

Dim Det01 As String 'Variable para almacenar valores de Det01

Dim Det02 As String 'Variable para almacenar valores de Det02

Dim Det03 As String 'Variable para almacenar valores de Det03

Dim Det04 As String 'Variable para almacenar valores de Det04

Dim Det05 As String 'Variable para almacenar valores de Det05

Dim Det06 As String 'Variable para almacenar valores de Det06

Dim Det07 As String 'Variable para almacenar valores de Det07

Dim Det08 As String 'Variable para almacenar valores de Det08

Dim Det09 As String 'Variable para almacenar valores de Det09

Dim Det10 As String 'Variable para almacenar valores de Det10

Dim Transporte As String 'Variable para almacenar valores de Transporte

Dim Transdire As String 'Variable para almacenar valores de TransporteDireccion

Dim Valor As String 'Variable para almacenar valores de Valor

Dim Bultos As String 'Variable para almacenar valores de Bultos

Cliente = TextCliente.Value 'Paso del formulario a la variable

Direccion = TextDireccion.Value 'Paso del formulario a la variable

Provincia = TextProvincia.Value 'Paso del formulario a la variable

Venta = TextVenta.Value 'Paso del formulario a la variable

Cuit = TextCuit.Text = Val(TextCuit.Text) 'Paso del formulario a la variable

Cant01 = TextCant01.Text = Val(TextCant01.Text) 'Paso del formulario a la variable

Cant02 = TextCant02.Text = Val(TextCant02.Text) 'Paso del formulario a la variable

Cant03 = TextCant03.Value 'Paso del formulario a la variable

Cant04 = TextCant04.Value 'Paso del formulario a la variable

Cant05 = TextCant05.Value 'Paso del formulario a la variable

Cant06 = TextCant06.Value 'Paso del formulario a la variable

Cant07 = TextCant07.Value 'Paso del formulario a la variable

Cant08 = TextCant08.Value 'Paso del formulario a la variable

Cant09 = TextCant09.Value 'Paso del formulario a la variable

Cant10 = TextCant10.Value 'Paso del formulario a la variable

Det01 = TextDet01.Value 'Paso del formulario a la variable

Det02 = TextDet02.Value 'Paso del formulario a la variable

Det03 = TextDet03.Value 'Paso del formulario a la variable

Det04 = TextDet04.Value 'Paso del formulario a la variable

Det05 = TextDet05.Value 'Paso del formulario a la variable

Det06 = TextDet06.Value 'Paso del formulario a la variable

Det07 = TextDet07.Value 'Paso del formulario a la variable

Det08 = TextDet08.Value 'Paso del formulario a la variable

Det09 = TextDet09.Value 'Paso del formulario a la variable

Det10 = TextDet10.Value 'Paso del formulario a la variable

Transporte = TextTransporte.Value 'Paso del formulario a la variable

Transdire = TextTransdire.Value 'Paso del formulario a la variable

Valor = TextValor.Value 'Paso del formulario a la variable

Bultos = TextBultos.Value 'Paso del formulario a la variable


ActiveSheet.Cells(4, 2) = TextCliente
ActiveSheet.Cells(4, 4) = TextDireccion
ActiveSheet.Cells(5, 4) = TextProvincia
ActiveSheet.Cells(6, 2) = TextVenta
ActiveSheet.Cells(6, 4) = TextCuit
ActiveSheet.Cells(8, 1) = TextCant01
ActiveSheet.Cells(8, 2) = TextDet01
ActiveSheet.Cells(9, 1) = TextCant02
ActiveSheet.Cells(9, 2) = TextDet02
ActiveSheet.Cells(10, 1) = TextCant03
ActiveSheet.Cells(10, 2) = TextDet03
ActiveSheet.Cells(11, 1) = TextCant04
ActiveSheet.Cells(11, 2) = TextDet04
ActiveSheet.Cells(12, 1) = TextCant05
ActiveSheet.Cells(12, 2) = TextDet05
ActiveSheet.Cells(13, 1) = TextCant06
ActiveSheet.Cells(13, 2) = TextDet06
ActiveSheet.Cells(14, 1) = TextCant07
ActiveSheet.Cells(14, 2) = TextDet07
ActiveSheet.Cells(15, 1) = TextCant08
ActiveSheet.Cells(15, 2) = TextDet08
ActiveSheet.Cells(16, 1) = TextCant09
ActiveSheet.Cells(16, 2) = TextDet09
ActiveSheet.Cells(17, 1) = TextCant10
ActiveSheet.Cells(17, 2) = TextDet10
ActiveSheet.Cells(21, 5) = TextValor
ActiveSheet.Cells(26, 2) = TextTransporte
ActiveSheet.Cells(26, 3) = TextBultos
ActiveSheet.Cells(27, 2) = TextTransdire

No funciono por tal motivo te paso lo que arme tal vez estoy cometiendo algún error 

Private Sub ComandIngreso_Click()

Dim Cliente As String 'Variable para almacenar valores de cliente

Dim Direccion As String 'Variable para almacenar valores de Direccion

Dim Provincia As String 'Variable para almacenar valores de Provincia

Dim Venta As String 'Variable para almacenar valores de Venta

Dim Cuit As String 'Variable para almacenar valores de Cuit

Dim Cant01 As String 'Variable para almacenar valores de Cantidad01

Dim Cant02 As String 'Variable para almacenar valores de Cantidad02

Dim Cant03 As String 'Variable para almacenar valores de Cantidad03

Dim Cant04 As String 'Variable para almacenar valores de Cantidad04

Dim Cant05 As String 'Variable para almacenar valores de Cantidad05

Dim Cant06 As String 'Variable para almacenar valores de Cantidad06

Dim Cant07 As String 'Variable para almacenar valores de Cantidad07

Dim Cant08 As String 'Variable para almacenar valores de Cantidad08

Dim Cant09 As String 'Variable para almacenar valores de Cantidad09

Dim Cant10 As String 'Variable para almacenar valores de Cantidad10

Dim Det01 As String 'Variable para almacenar valores de Det01

Dim Det02 As String 'Variable para almacenar valores de Det02

Dim Det03 As String 'Variable para almacenar valores de Det03

Dim Det04 As String 'Variable para almacenar valores de Det04

Dim Det05 As String 'Variable para almacenar valores de Det05

Dim Det06 As String 'Variable para almacenar valores de Det06

Dim Det07 As String 'Variable para almacenar valores de Det07

Dim Det08 As String 'Variable para almacenar valores de Det08

Dim Det09 As String 'Variable para almacenar valores de Det09

Dim Det10 As String 'Variable para almacenar valores de Det10

Dim Transporte As String 'Variable para almacenar valores de Transporte

Dim Transdire As String 'Variable para almacenar valores de TransporteDireccion

Dim Valor As String 'Variable para almacenar valores de Valor

Dim Bultos As String 'Variable para almacenar valores de Bultos

Cliente = TextCliente.Value 'Paso del formulario a la variable

Direccion = TextDireccion.Value 'Paso del formulario a la variable

Provincia = TextProvincia.Value 'Paso del formulario a la variable

Venta = TextVenta.Value 'Paso del formulario a la variable

Cuit = TextCuit.Text = Val(TextCuit.Text) 'Paso del formulario a la variable

Cant01 = TextCant01.Text = Val(TextCant01.Text) 'Paso del formulario a la variable

Cant02 = TextCant02.Text = Val(TextCant02.Text) 'Paso del formulario a la variable

Cant03 = TextCant03.Value 'Paso del formulario a la variable

Cant04 = TextCant04.Value 'Paso del formulario a la variable

Cant05 = TextCant05.Value 'Paso del formulario a la variable

Cant06 = TextCant06.Value 'Paso del formulario a la variable

Cant07 = TextCant07.Value 'Paso del formulario a la variable

Cant08 = TextCant08.Value 'Paso del formulario a la variable

Cant09 = TextCant09.Value 'Paso del formulario a la variable

Cant10 = TextCant10.Value 'Paso del formulario a la variable

Det01 = TextDet01.Value 'Paso del formulario a la variable

Det02 = TextDet02.Value 'Paso del formulario a la variable

Det03 = TextDet03.Value 'Paso del formulario a la variable

Det04 = TextDet04.Value 'Paso del formulario a la variable

Det05 = TextDet05.Value 'Paso del formulario a la variable

Det06 = TextDet06.Value 'Paso del formulario a la variable

Det07 = TextDet07.Value 'Paso del formulario a la variable

Det08 = TextDet08.Value 'Paso del formulario a la variable

Det09 = TextDet09.Value 'Paso del formulario a la variable

Det10 = TextDet10.Value 'Paso del formulario a la variable

Transporte = TextTransporte.Value 'Paso del formulario a la variable

Transdire = TextTransdire.Value 'Paso del formulario a la variable

Valor = TextValor.Value 'Paso del formulario a la variable

Bultos = TextBultos.Value 'Paso del formulario a la variable


ActiveSheet.Cells(4, 2) = TextCliente
ActiveSheet.Cells(4, 4) = TextDireccion
ActiveSheet.Cells(5, 4) = TextProvincia
ActiveSheet.Cells(6, 2) = TextVenta
ActiveSheet.Cells(6, 4) = TextCuit
ActiveSheet.Cells(8, 1) = TextCant01
ActiveSheet.Cells(8, 2) = TextDet01
ActiveSheet.Cells(9, 1) = TextCant02
ActiveSheet.Cells(9, 2) = TextDet02
ActiveSheet.Cells(10, 1) = TextCant03
ActiveSheet.Cells(10, 2) = TextDet03
ActiveSheet.Cells(11, 1) = TextCant04
ActiveSheet.Cells(11, 2) = TextDet04
ActiveSheet.Cells(12, 1) = TextCant05
ActiveSheet.Cells(12, 2) = TextDet05
ActiveSheet.Cells(13, 1) = TextCant06
ActiveSheet.Cells(13, 2) = TextDet06
ActiveSheet.Cells(14, 1) = TextCant07
ActiveSheet.Cells(14, 2) = TextDet07
ActiveSheet.Cells(15, 1) = TextCant08
ActiveSheet.Cells(15, 2) = TextDet08
ActiveSheet.Cells(16, 1) = TextCant09
ActiveSheet.Cells(16, 2) = TextDet09
ActiveSheet.Cells(17, 1) = TextCant10
ActiveSheet.Cells(17, 2) = TextDet10
ActiveSheet.Cells(21, 5) = TextValor
ActiveSheet.Cells(26, 2) = TextTransporte
ActiveSheet.Cells(26, 3) = TextBultos
ActiveSheet.Cells(27, 2) = TextTransdire

los datos que quieres como valor los tienes declarados como string y cada que quieras usar estos valores como numeros te va a marcar un error, cambia el string de esos campos por single (entero con decimales), long(enteros largos), integer(enteros cortos) o double(enteros con doble decimal) por ejemplo dim bultos as single, esta instruccion no la entiendo Cuit = TextCuit.Text = Val(TextCuit.Text), yo la programaria asi cuit=val(textcuit.text)

Realice los cambio que me sugeriste pero los toma como texto y necesito que los tome como números

Viendo tu macro encuentro lo siguiente como dije los valores numéricos deben ser declarados como dim por as single tu los tienes como string (formato texto), luego declararas variables de memoria cant01=textcant01 con un val o un .value y aquí viene lo irónico cuando capturas no usas .cells(4,2)=cant01 sino que capturas directamente el textbox el cual sigue teniendi los campos como texto, prueba la macro y ve por ti mismo lo que te digo ahora con unas cuantas modificaciones ya pega los números como números y no como texto

Private Sub ComandIngreso_Click()
Dim Cliente As String, Direccion As String, Provincia As String
Dim Venta As Single, Cuit As Single, Cant01 As Single, Cant02 As Single
Dim Cant03 As Single, Cant04 As Single, Cant05 As Single
Dim Cant06 As Single, Cant07 As Single, Cant08 As Single
Dim Cant09 As Single, Cant10 As Single, Det01 As Single
Dim Det02 As Single, Det03 As Single, Det04 As Single
Dim Det05 As Single, Det06 As Single, Det07 As Single
Dim Det08 As Single, Det09 As Single, Det10 As Single
Dim Valor As Single, bultos As Single
Dim Transporte As String 'Variable para almacenar valores de Transporte
Dim Transdire As String 'Variable para almacenar valores de TransporteDireccion
Cliente = TextCliente.Value 'Paso del formulario a la variable
Direccion = TextDireccion.Value 'Paso del formulario a la variable
Provincia = TextProvincia.Value 'Paso del formulario a la variable
Venta = TextVenta.Value 'Paso del formulario a la variable
Cuit = Val(TextCuit.Text) 'Paso del formulario a la variable
Cant01 = Val(TextCant01.Text) 'Paso del formulario a la variable
Cant02 = Val(TextCant02.Text) 'Paso del formulario a la variable
Cant03 = Val(TextCant03.Text)  'Paso del formulario a la variable
Cant04 = Val(TextCant04.Text) 'Paso del formulario a la variable
Cant05 = Val(TextCant05.Text) 'Paso del formulario a la variable
Cant06 = Val(TextCant06.Text) 'Paso del formulario a la variable
Cant07 = Val(TextCant07.Text) 'Paso del formulario a la variable
Cant08 = Val(TextCant08.Text) 'Paso del formulario a la variable
Cant09 = Val(TextCant09.Text) 'Paso del formulario a la variable
Cant10 = Val(TextCant10.Text) 'Paso del formulario a la variable
Det01 = Val(TextDet01.Text) 'Paso del formulario a la variable
Det02 = Val(TextDet02.Text) 'Paso del formulario a la variable
Det03 = Val(TextDet03.Text) 'Paso del formulario a la variable
Det04 = Val(TextDet04.Text) 'Paso del formulario a la variable
Det05 = Val(TextDet05.Text) 'Paso del formulario a la variable
Det06 = Val(TextDet06.Text) 'Paso del formulario a la variable
Det07 = Val(TextDet07.Text) 'Paso del formulario a la variable
Det08 = Val(TextDet08.Text) 'Paso del formulario a la variable
Det09 = Val(TextDet09.Text) 'Paso del formulario a la variable
Det10 = Val(TextDet10.Text) 'Paso del formulario a la variable
Transporte = TextTransporte.Value 'Paso del formulario a la variable
Transdire = TextTransdire.Value 'Paso del formulario a la variable
Valor = TextValor.Value 'Paso del formulario a la variable
bultos = TextBultos.Value 'Paso del formulario a la variable
With ActiveSheet
    .Cells(4, 2) = TextCliente
    .Cells(4, 4) = TextDireccion
    .Cells(5, 4) = TextProvincia
    .Cells(6, 2) = Venta
    .Cells(6, 4) = Cuit
    .Cells(8, 1) = Cant01
    .Cells(8, 2) = Det01
    .Cells(9, 1) = Cant02
    .Cells(9, 2) = Det02
    .Cells(10, 1) = Cant03
    .Cells(10, 2) = Det03
    .Cells(11, 1) = Cant04
    .Cells(11, 2) = Det04
    .Cells(12, 1) = Cant05
    .Cells(12, 2) = Det05
    .Cells(13, 1) = Cant06
    .Cells(13, 2) = Det06
    .Cells(14, 1) = Cant07
    .Cells(14, 2) = Det07
    .Cells(15, 1) = Cant08
    .Cells(15, 2) = Det08
    .Cells(16, 1) = Cant09
    .Cells(16, 2) = Det09
    .Cells(17, 1) = Cant10
    .Cells(17, 2) = Det10
    .Cells(21, 5) = Valor
    .Cells(26, 2) = Transporte
    .Cells(26, 3) = bultos
    .Cells(27, 2) = Transdire
End With
End Sub

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas