Modificar código de formulario excel
buenas e estado haciendo un trabajo en excel y quiero modificar una parte del código que no se como modificarlo, tengo un buscador con una listbox en ese mismo formulario hay dos botones modificar y eliminar datos al seleccionar una de estas filas del listbox me inserta los datos en alguno de estos formularios, los códigos están buenos.
la cuestión es que modifique un poco el proyecto y elimine el buscador pues el filtro lo hice desde la hoja excel, y quiero poder insertar los datos desde la hoja y no desde el listbox del buscador y no se que debo modificar pues parte del código no es mio
Dim BD As Worksheet, RG As Worksheet, Fila As Long '================================= BOTON DE INGRESO DATOS ================================= '========================================================================================== Private Sub BtnGrabarDatos_Click() X = RG.Range( F & Rows.Count).End(xlUp).Row + 1 If MoJustificación.Value = Then MsgBox Debe poner la justificación Else BD.Rows(Fila).Copy RG.Rows(X) RG.Range( O & X) = Date RG.Range( P & X) = MoEstado.Text RG.Range( Q & X) = MoMotivo.Text RG.Range( R & X) = MoJustificación BD.Cells(Fila, 2) = CDbl(MoCodigo) BD.Cells(Fila, 3) = MoCategoria If IsNumeric(MoFactura) Then BD.Cells(Fila, 4) = CDbl(MoFactura) Else BD.Cells(Fila, 4) = MoFactura End If If IsNumeric(MoReferencia) Then BD.Cells(Fila, 7) = CDbl(MoReferencia) Else BD.Cells(Fila, 7) = MoReferencia End If BD.Cells(Fila, 8) = MoDescripcion BD.Cells(Fila, 9) = MoEstado.Text BD.Cells(Fila, 10) = MoFecha BD.Cells(Fila, 12) = Date BD.Cells(Fila, 13) = CDbl(MoUnitario) Unload Me End If End Sub '==================================== BOTON DE REGRESO ==================================== '========================================================================================== Private Sub BtnRegresar_Click() Unload Me End Sub '================================ MOSTRAR, OCULTAR BOTONES ================================ '========================================================================================== Private Sub ChecVerificado_Click() If ChecVerificado.Value = True Then BtnGrabarDatos.Visible = True BtnRegresar.Visible = False Else BtnGrabarDatos.Visible = False BtnRegresar.Visible = True End If End Sub Private Sub UserForm_Activate() If FmBuscador.Visible = False Then Unload Me End Sub '==================================== CARGAR LOS DATOS ==================================== '========================================================================================== Private Sub UserForm_Initialize() On Error Resume Next Application.ScreenUpdating = False Set BD = Sheets( BASE DE DATOS ) Set RG = Sheets( REGISTRO ) K.RowSource = F5:F & Range( F & Rows.Count).End(xlUp).Row K.Text = FmBuscador.ListBox1.List(FmBuscador.ListBox1.ListIndex, 4) Fila = K.ListIndex + 5 ufh = Sheets( CODIGOS ).Range( H & Cells.Rows.Count).End(xlUp).Row ufi = Sheets( CODIGOS ).Range( I & Cells.Rows.Count).End(xlUp).Row hojactiva = ActiveSheet.Name unicosparacombobox With Sheets( CARGA ) Me.MoCategoria.List() = .Range( A1 , .Range( A1 ).End(xlDown)).Value .Columns( A ).ClearContents End With Sheets(hojactiva).Activate MoEstado.RowSource = CODIGOS!H5:H & ufh MoMotivo.RowSource = CODIGOS!I5:I & ufi MoInventario = BD.Cells(Fila, 6) MoCantidad = BD.Cells(Fila, 5) MoCodigo = BD.Cells(Fila, 2) MoCategoria = BD.Cells(Fila, 3) MoFactura = BD.Cells(Fila, 4) MoReferencia = BD.Cells(Fila, 7) MoDescripcion = BD.Cells(Fila, 8) MoEstado.Text = BD.Cells(Fila, 9) MoFecha = BD.Cells(Fila, 10) MoUnitario = BD.Cells(Fila, 13) MoMotivo = MoJustificación = EstyloTitulo Me.Caption Me.Height = Me.Height - 18 Application.ScreenUpdating = True End Sub '============================== MUESTRA CODIGO CON CATEGORIA ============================== '========================================================================================== Private Sub MoCategoria_Change() On Error Resume Next Dim nombre As Range Dim Rango As Range Set Rango = Sheets( CODIGOS ).Range( C5:C & uf) Set nombre = Rango.Find(what:=Me.MoCategoria, _ LookIn:=xlValues, Lookat:=xlWhole) Me.MoCodigo = nombre.Offset(, -1) Set Rango = Nothing Set nombre = Nothing End Sub '=================================== MOSTRAR CALENDARIO =================================== '========================================================================================== Private Sub Calendario() 'Condiciones para llamar al FmCalendario Fecha = Empty FmCalendario.Show MoFecha = If Fecha <> Empty Then MoFecha = Fecha End Sub Private Sub MoFecha_Click() 'Llama e inserta fecha en el label IFeCompra Calendario End Sub
el código funciona muy bien con el buscador pero quiero cambiar la forma de insertar los datos , en vez desde el buscador sea desde la fila seleccionada en la hoja BASE DE DATOS
les agradecería muchísimo su ayuda