Error al ejecutar un formulario desde el editor VBA de Excel
Me puedes ayudar con este tema cuando ejecuto un formulario desde el editor de VBA de Excel me aparece el siguiente error en el método "select" de objeto "_worksheet
1 respuesta
Respuesta de Dante Amor
1
1
Dante Amor, https://www.youtube.com/@CursosDeExcelyMacros
¿Alguna línea de la macro se pone de color azul o de color amarillo?
Puedes poner toda la macro para probarla.
hola dante
te adjunto todo el código del formulario creo que he ingresado demasiados valores y el error no me lo encuentro
le adjunto la respuesta anterior que me brindo para que pueda entender mejor lo que estoy elaborando
Option Explicit Private Sub AÑADIR_Click() Dim x As Integer Dim Y As Integer Dim fecha As Double Dim Articulo As String Dim Referencia As String Dim Cantidad As String Dim npedido, familia, tipoinsumo, um, cocina, servicio, caja, bar, postres, otros As String Dim dato As String Dim contarsi As String Dim numero As String Dim resp As Byte 'Application.ScreenUpdating = False Sheets("inicio1").Select ActiveSheet.Unprotect "" 'If ComboBox3.Text = "" Then 'MsgBox " Debe informar la referencia del Producto ", vbCritical, "Informacion" 'ComboBox3.SetFocus 'Exit Sub 'End If If TextBox15.Text = "" Then MsgBox " Debe informar el nombre del Producto ", vbCritical, "Informacion" ComboBox11.SetFocus Exit Sub End If 'validamos si hay duplicados If TextBox16 = "0" And TextBox17 = "0" And TextBox18 = "0" And TextBox19 = "0" And TextBox20 = "0" And TextBox26 = "0" Then MsgBox "Todos los campos no pueden tener 0 VERIFICAR" 'Sheets("inicio").Select 'Hoja1.TextBox2.BackColor = &HFF00& TextBox16.SetFocus Exit Sub End If dato = TextBox25.Value contarsi = Application.WorksheetFunction.CountIf(Sheets("inicio1").Columns(3), dato) If contarsi > 0 Then 'UserForm3.Show resp = MsgBox("¿El nombre ya exixte deseas revisar y actualizar?", _ vbQuestion + vbYesNo, "EXCELeINFO") 'MsgBox "El nombre ya exixte revisar y actualizar" 'ComboBox11.SetFocus If resp = vbYes Then UserForm4.Show Else UserForm2.Hide UserForm2.Show 'ComboBox11.SetFocus Exit Sub End If Else numero = Application.WorksheetFunction.CountA(Sheets("INICIO1").Range("A8:a1000")) npedido = ComboBox4.Value Referencia = ComboBox3.Value Articulo = ComboBox11.Value familia = TextBox10.Value tipoinsumo = TextBox12.Value um = TextBox15.Value cocina = TextBox16.Value servicio = TextBox17.Value caja = TextBox18.Value bar = TextBox19.Value postres = TextBox20.Value fecha = DTPicker2.Value otros = TextBox26.Value ActiveWorkbook.Sheets("Inicio1").Visible = True Sheets("Inicio1").Activate End If For Y = 9 To 900 If Y = 901 Then MsgBox "Demasiados Articulos", vbInformation NUEVO_Click Exit Sub End If ActiveSheet.Unprotect "" If (Cells(Y, 3)) = "" Then Cells(Y, 1).Select Cells(Y, 1).Value = numero Cells(Y, 2).Select Cells(Y, 2).Value = Referencia Cells(Y, 3).Select Cells(Y, 3).Value = Articulo ' Cells(Y, 4).Select ' Cells(Y, 5).Value = Precio Cells(Y, 4).Select Cells(Y, 4).Value = tipoinsumo Cells(Y, 5).Select Cells(Y, 5).Value = fecha Cells(Y, 6).Select Cells(Y, 6).Value = familia Cells(Y, 7).Select Cells(Y, 7).Value = um Cells(Y, 8).Select Cells(Y, 8).Value = cocina Cells(Y, 9).Select Cells(Y, 9).Value = servicio Cells(Y, 10).Select Cells(Y, 10).Value = caja Cells(Y, 11).Select Cells(Y, 11).Value = bar Cells(Y, 12).Select Cells(Y, 12).Value = postres Cells(Y, 13).Select Cells(Y, 13).Value = otros Cells(Y, 14).Select Cells(Y, 14).Value = Val(TextBox16) + Val(TextBox17) + Val(TextBox18) + Val(TextBox19) + Val(TextBox20) + Val(TextBox26) Exit For End If Next Y ActiveSheet.Protect "" NUEVO_Click Sheets("inicio1").Activate End Sub Private Sub CERRAR_Click() Unload Me End Sub Private Sub NUEVO_Click() ComboBox3.Text = "" ComboBox11.Text = "" 'Application.ScreenUpdating = False Dim x As Integer Dim control As String Dim indice As String For x = 0 To Controls.Count - 1 If Left(Controls(x).Name, 7) = "TextBox" Then control = Controls(x).Name indice = Val(Right(control, Len(control) - InStrRev(control, "x"))) Controls(x).Value = "" End If Next x ComboBox11.SetFocus End Sub Private Sub ComboBox11_Change() On Error Resume Next Dim marca As String Dim idbusca As String Dim fila As Integer Application.ScreenUpdating = False Sheets("insumos").Select Hoja2.Visible = xlSheetVisible fila = 0 marca = ComboBox11.Value Do While idbusca <> marca fila = fila + 1 idbusca = Range("B" & fila).Value If idbusca = Empty Then Sheets("inicio1").Select MsgBox "No se encontraron datos" Exit Do End If Loop ComboBox3.Value = Range("A" & fila).Value 'ComboBox15.Value = Range("e" & fila).Value TextBox10.Value = Range("c" & fila).Value TextBox15.Value = Range("e" & fila).Value TextBox12.Value = Range("f" & fila).Value TextBox25.Value = Range("B" & fila).Value TextBox16.Value = 0 TextBox17.Value = 0 TextBox18.Value = 0 TextBox19.Value = 0 TextBox20.Value = 0 TextBox26.Value = 0 'Hoja1.Activate If ComboBox11.Value = "" Then TextBox25.Text = "" ComboBox3.Value = "" TextBox16.Value = "" TextBox17.Value = "" TextBox18.Value = "" TextBox19.Value = "" TextBox20.Value = "" TextBox26.Value = "" Else TextBox25.Value = Range("B" & fila).Value TextBox16.Value = 0 TextBox17.Value = 0 TextBox18.Value = 0 TextBox19.Value = 0 TextBox20.Value = 0 TextBox26.Value = 0 End If Sheets("Inicio1").Activate Application.ScreenUpdating = True End Sub Private Sub ComboBox3_Change() On Error Resume Next Dim marca As String Dim idbusca As String Dim fila As Integer 'Application.ScreenUpdating = False Sheets("insumos").Select Hoja2.Visible = xlSheetVisible fila = 0 marca = ComboBox3.Value Do While idbusca <> marca fila = fila + 1 idbusca = Range("A" & fila).Value If idbusca = Empty Then Sheets("inicio1").Select MsgBox "No se encontraron datos" Exit Do End If Loop ComboBox11.Value = Range("B" & fila).Value 'ComboBox15.Value = Range("e" & fila).Value TextBox10.Value = Range("c" & fila).Value TextBox15.Value = Range("e" & fila).Value TextBox12.Value = Range("f" & fila).Value TextBox25.Value = Range("B" & fila).Value TextBox16.Value = 0 TextBox17.Value = 0 TextBox18.Value = 0 TextBox19.Value = 0 TextBox20.Value = 0 TextBox26.Value = 0 If ComboBox3.Value = "" Then TextBox25.Text = "" ComboBox11.Value = "" TextBox10.Text = "" TextBox12.Text = "" TextBox15.Text = "" TextBox16.Value = "" TextBox17.Value = "" TextBox18.Value = "" TextBox19.Value = "" TextBox20.Value = "" TextBox26.Value = "" Else TextBox25.Value = Range("B" & fila).Value ComboBox11.Value = Range("B" & fila).Value 'ComboBox15.Value = Range("e" & fila).Value TextBox10.Value = Range("c" & fila).Value TextBox15.Value = Range("e" & fila).Value TextBox12.Value = Range("f" & fila).Value TextBox16.Value = 0 TextBox17.Value = 0 TextBox18.Value = 0 TextBox19.Value = 0 TextBox20.Value = 0 TextBox26.Value = 0 End If Application.ScreenUpdating = True End Sub Private Sub UserForm_Click() End Sub Private Sub UserForm_Initialize() Sheets("inicio1").Select ActiveSheet.Unprotect "" TextBox25.Text = "" ComboBox11.Value = "" TextBox10.Text = "" TextBox12.Text = "" TextBox15.Text = "" TextBox16.Value = "" TextBox17.Value = "" TextBox18.Value = "" TextBox19.Value = "" TextBox20.Value = "" TextBox26.Value = "" DTPicker2.Value = Sheets("inicio1").Range("o1").Value Dim B2 As Range Dim a2 As Range Application.ScreenUpdating = False ordenar_arrastre Hoja2.Visible = xlSheetVisible Hoja2.Select Range("B2").Select While ActiveCell <> "" ComboBox11.AddItem ActiveCell ActiveCell.Offset(1, 0).Select Wend ordenar_arrastre Hoja6.Select Range("E9").Select ComboBox11.SetFocus '................. ordenar_arrastre Hoja2.Select Range("A2").Select While ActiveCell <> "" ComboBox3.AddItem ActiveCell ActiveCell.Offset(1, 0).Select Wend ordenar_arrastre Hoja6.Select Range("E9").Select '................. Sheets("inicio1").Select ActiveSheet.Protect "" Application.ScreenUpdating = True End Sub Private Sub TextBox16_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) 'Por.Dante Amor Select Case KeyCode Case 8, 46: TextBox16 = Mid(TextBox16, 1, TextBox16.SelStart) End Select End Sub Private Sub TextBox16_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) Dim n, d, lpunto As Integer n = 5 'cantidad de entero d = 2 'cantidad de decimales lpunto = InStr(1, TextBox16, ".") Select Case KeyAscii Case Is < 46, Is > 57, 47: KeyAscii = 0 Case 46: If lpunto > 0 Then KeyAscii = 0 Case Is >= 48, Is <= 57 If lpunto > 0 Then If Len(Mid(TextBox16, lpunto + 1)) = d And TextBox16.SelStart >= lpunto Then KeyAscii = 0 If Len(TextBox16) = n + d + 1 Then KeyAscii = 0 Else If Len(TextBox16) = n Then KeyAscii = 0 End If End Select End Sub Private Sub TextBox17_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) 'Por.Dante Amor Select Case KeyCode Case 8, 46: TextBox17 = Mid(TextBox17, 1, TextBox17.SelStart) End Select End Sub Private Sub TextBox17_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) Dim n, d, lpunto As Integer n = 5 'cantidad de entero d = 2 'cantidad de decimales lpunto = InStr(1, TextBox17, ".") Select Case KeyAscii Case Is < 46, Is > 57, 47: KeyAscii = 0 Case 46: If lpunto > 0 Then KeyAscii = 0 Case Is >= 48, Is <= 57 If lpunto > 0 Then If Len(Mid(TextBox17, lpunto + 1)) = d And TextBox17.SelStart >= lpunto Then KeyAscii = 0 If Len(TextBox17) = n + d + 1 Then KeyAscii = 0 Else If Len(TextBox17) = n Then KeyAscii = 0 End If End Select End Sub Private Sub TextBox18_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) 'Por.Dante Amor Select Case KeyCode Case 8, 46: TextBox18 = Mid(TextBox18, 1, TextBox18.SelStart) End Select End Sub Private Sub TextBox18_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) Dim n, d, lpunto As Integer n = 5 'cantidad de entero d = 2 'cantidad de decimales lpunto = InStr(1, TextBox18, ".") Select Case KeyAscii Case Is < 46, Is > 57, 47: KeyAscii = 0 Case 46: If lpunto > 0 Then KeyAscii = 0 Case Is >= 48, Is <= 57 If lpunto > 0 Then If Len(Mid(TextBox18, lpunto + 1)) = d And TextBox18.SelStart >= lpunto Then KeyAscii = 0 If Len(TextBox18) = n + d + 1 Then KeyAscii = 0 Else If Len(TextBox18) = n Then KeyAscii = 0 End If End Select End Sub Private Sub TextBox19_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) 'Por.Dante Amor Select Case KeyCode Case 8, 46: TextBox19 = Mid(TextBox19, 1, TextBox19.SelStart) End Select End Sub Private Sub TextBox19_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) Dim n, d, lpunto As Integer n = 5 'cantidad de entero d = 2 'cantidad de decimales lpunto = InStr(1, TextBox19, ".") Select Case KeyAscii Case Is < 46, Is > 57, 47: KeyAscii = 0 Case 46: If lpunto > 0 Then KeyAscii = 0 Case Is >= 48, Is <= 57 If lpunto > 0 Then If Len(Mid(TextBox19, lpunto + 1)) = d And TextBox19.SelStart >= lpunto Then KeyAscii = 0 If Len(TextBox19) = n + d + 1 Then KeyAscii = 0 Else If Len(TextBox19) = n Then KeyAscii = 0 End If End Select End Sub Private Sub TextBox20_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) 'Por.Dante Amor Select Case KeyCode Case 8, 46: TextBox20 = Mid(TextBox20, 1, TextBox20.SelStart) End Select End Sub Private Sub TextBox20_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) Dim n, d, lpunto As Integer n = 5 'cantidad de entero d = 2 'cantidad de decimales lpunto = InStr(1, TextBox20, ".") Select Case KeyAscii Case Is < 46, Is > 57, 47: KeyAscii = 0 Case 46: If lpunto > 0 Then KeyAscii = 0 Case Is >= 48, Is <= 57 If lpunto > 0 Then If Len(Mid(TextBox20, lpunto + 1)) = d And TextBox20.SelStart >= lpunto Then KeyAscii = 0 If Len(TextBox20) = n + d + 1 Then KeyAscii = 0 Else If Len(TextBox20) = n Then KeyAscii = 0 End If End Select End Sub Private Sub TextBox26_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) 'Por.Dante Amor Select Case KeyCode Case 8, 46: TextBox26 = Mid(TextBox26, 1, TextBox26.SelStart) End Select End Sub Private Sub TextBox26_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) Dim n, d, lpunto As Integer n = 5 'cantidad de entero d = 2 'cantidad de decimales lpunto = InStr(1, TextBox26, ".") Select Case KeyAscii Case Is < 46, Is > 57, 47: KeyAscii = 0 Case 46: If lpunto > 0 Then KeyAscii = 0 Case Is >= 48, Is <= 57 If lpunto > 0 Then If Len(Mid(TextBox26, lpunto + 1)) = d And TextBox26.SelStart >= lpunto Then KeyAscii = 0 If Len(TextBox26) = n + d + 1 Then KeyAscii = 0 Else If Len(TextBox26) = n Then KeyAscii = 0 End If End Select End Sub
atte.
Robert
Mejor envíame el archivo, para poder reproducir el erro.
Mi correo [email protected]
En el asunto del correo escribe tu nombre de usuario “Robert Cordova Cordova” y el título de esta pregunta.
- Compartir respuesta
- Anónimo
ahora mismo