Carga de datos en formulario Excel para editar

Y muchas gracias de antemano por la ayuda que puedan brindarme.

Tengo un formulario de Excel para ingresar, buscar, editar y eliminar registros de una Hoja de cálculo.

Funciona perfecto, pero a la hora de seleccionar un registro en el Listbox, los campos que tienen combobox y checkbox no me aparece lo ya ingresado para poder editarlo.

No se si debo ingresarles el código que tengo para el Botón editar o el botón Ingresar.

2 Respuestas

Respuesta
4

No se si debo ingresarles el código que tengo para el Botón editar o el botón Ingresar.

Sí, por favor, pon todo tu código.

O mejor aún, si puedes compartir tu archivo en google drive, comparte el enlace para cualquiera, copia el enlace y pega aquí.

Si tu archivo tiene información confidencial, reemplaza por datos genéricos.

Explica en alguna hoja brevemente el funcionamiento de tu formulario y en dónde tienes problemas, es decir, qué realizas en el formulario y cuál resultado esperas.

Hola, muchas gracias por la respuesta de ambos. La de Elsa no la entiendo bien y no se dónde poner el código y como modificarlo, pero entiendo que ella tampoco tiene el código para ayudarme, así que subo el archivo a google drive para ver si me pueden ayudar.

https://docs.google.com/spreadsheets/d/1NJe6BRDpA8IYG5G3bh9X_Zyy39ON481hk8p4HbaXg90/edit?usp=sharing 

Muchas gracias nuevamente

Te envié una solicitud para poder descargar el archivo.


Nota: En el futuro, para insertar código aquí en el foro, puedes utilizar el icono para insertar código:

Después de presionar el icono, te abre un panel:

Ahí puedes pegar el código y después presionar OK.

El código quedará de esta manera:

Sub SearchForString()
'Por Dante Amor
  Dim wrd As Variant, arr As Variant
  Dim fnd As Range, cpy As Range, rng As Range
  Dim myPath As String, addr As String, sFile As String, sheetName As String
  Dim wb2 As Workbook
  Dim shd As Worksheet
  Application.ScreenUpdating = False
  arr = Array("transfer", "indicate", "water")    'populate the array for the outer loop
  sheetName = "Sheet1"                            'Source sheet
  Set shd = Sheets("Sheet2")                      'destination sheet
  With Application.FileDialog(msoFileDialogFolderPicker)    'To select the folder
    .Title = "Select Folder"
    .AllowMultiSelect = False
    If .Show <> -1 Then Exit Sub
    myPath = .SelectedItems(1)
  End With
  sFile = Dir(myPath & "\" & "*.xls*")
  Do While sFile <> ""
    If HasSheet(myPath, sFile, sheetName) Then                  'validates that sheet1 exists
      Set wb2 = Workbooks.Open(myPath & "\" & sFile)
      Set cpy = Nothing
      Set rng = wb2.Sheets(sheetName).Range("B:B")              'Set column B to search
      For Each wrd In arr                                       'loop each word in the array
        Set fnd = rng.Find(wrd, , xlValues, xlPart, , , False)  'locate first instance
        If Not fnd Is Nothing Then
          addr = fnd.Address                                    'record address of first find
          If cpy Is Nothing Then Set cpy = fnd.Offset(, 1)      'seed the cpy range object
          Do
            Set cpy = Union(cpy, fnd.Offset(, 1))               'build union
            Set fnd = rng.FindNext(after:=fnd)                  'look for another
          Loop While Not fnd Is Nothing And fnd.Address <> addr
        End If
      Next
      If Not cpy Is Nothing Then cpy.Copy shd.Range("A" & Rows.Count).End(3)(2)
      wb2.Close False
    End If
    sFile = Dir()
  Loop
  Application.ScreenUpdating = True
  MsgBox "All matching data has been copied."
End Sub
Function HasSheet(fPath As String, fName As String, sheetName As String)
  Dim f As String
  f = "'" & fPath & "\[" & fName & "]" & sheetName & "'!R1C1"
  HasSheet = Not IsError(Application.ExecuteExcel4Macro(f))
End Function

NOTA: El código que puse es solamente un ejemplo de cómo queda el código en el foro, no tiene que ver con la respuesta.

Hola Dante, se como subirlo, solo que me pediste que te pusiera el archivo en Google Drive.

No me llegó el mail de solicitud, a ver si ahora te lo deja bajar.

https://docs.google.com/spreadsheets/d/1NJe6BRDpA8IYG5G3bh9X_Zyy39ON481hk8p4HbaXg90/edit?usp=sharing 

Ya pude entrar al archivo, pero no trae las macros.

Solamente lo puedo descargar como excel.

O envíame tu archivo a mi correo:

[email protected]

Modifiqué estos eventos:

Private Sub listbox_Click()
  Dim f As Range
  Set f = Hoja9.Range("A:A").Find(listbox.List(listbox.ListIndex), , xlValues, xlWhole)
  If Not f Is Nothing Then
    ID = Hoja9.Cells(f.Row, 1)
    rnos = Hoja9.Cells(f.Row, 2)
    expediente = Hoja9.Cells(f.Row, 3)
    fechaingreso = Hoja9.Cells(f.Row, 4)
    ejercicio = Hoja9.Cells(f.Row, 5)
    tramite = Hoja9.Cells(f.Row, 6)
    condicion = Hoja9.Cells(f.Row, 7)
    reso = Hoja9.Cells(f.Row, 8)
    sigla = Hoja9.Cells(f.Row, 9)
    nombreos = Hoja9.Cells(f.Row, 10)
    analista = Hoja9.Cells(f.Row, 11)
    cuit = Hoja9.Cells(f.Row, 12)
    año = Hoja9.Cells(f.Row, 13)
    periodo = Hoja9.Cells(f.Row, 14)
    email = Hoja9.Cells(f.Row, 15)
    inicioperiodo = Hoja9.Cells(f.Row, 16)
    finperiodo = Hoja9.Cells(f.Row, 17)
    dispo = Hoja9.Cells(f.Row, 18)
    fechadispo = Hoja9.Cells(f.Row, 19)
  End If
End Sub
'
Private Sub UserForm_Initialize()
  Dim lr As Long, i As Long
  lr = Hoja9.Range("A:A").Find("*", , xlValues, , xlByRows, xlPrevious).Row
  If Hoja9.Cells(2, 1) = Empty Then
    ID.Value = 1
  Else
    ID.Value = Hoja9.Cells(lr, 1) + 1
  End If
  With listbox
    .ColumnCount = 8
    .ColumnWidths = "40 pt;40 pt;170 pt;70 pt;60 pt;60 pt;80 pt;60 pt"
    For i = 2 To lr
      . AddItem
      . List(.ListCount - 1, 0) = Hoja9. Cells(i, 1) 'CODIGO
      . List(.ListCount - 1, 1) = Hoja9. Cells(i, 2) 'RNOS
      . List(.ListCount - 1, 2) = Hoja9. Cells(i, 3) 'EXPEDIENTE
      . List(.ListCount - 1, 3) = Hoja9. Cells(i, 4) 'FECHA INGRESO
      . List(.ListCount - 1, 4) = Hoja9. Cells(i, 5) 'EJERCICIO
      . List(.ListCount - 1, 5) = Hoja9. Cells(i, 6) 'TRAMITE
      . List(.ListCount - 1, 6) = Hoja9. Cells(i, 7) 'CONDICION
      . List(.ListCount - 1, 7) = Hoja9. Cells(i, 8) 'RESO
    Next i
  End With
End Sub
Respuesta
2

Seguramente en alguna columna de tu hoja se indica el valor del checkbox.

Entonces al traer todos los datos, debes hacer una evaluación. Algo así:

If range("H" & x) = "SI" then Checkbox1.value = True

Espero te sirva la aclaración, sino tendrás que dejar tu código para que pueda ajustarlo.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas