Cargar información que se encuentra almacenada en Celdas con base en la selección de un ComboBox.

Private Sub cbo_Nombre_Change()
On Error Resume Next

If CmdEditar <> "" Then
CmdEditar.Visible = True
cmd_Agregar.Visible = False
cmd_Eliminar.Enabled = True
Else
CmdEditar.Visible = False
cmd_Agregar.Visible = True
cmd_Eliminar.Enabled = False
End If

If cbo_Nombre = "" Then
cmd_Eliminar.Enabled = False
CmdEditar.Visible = False
cmd_Agregar.Visible = True
Else
TxtNombres.Enabled = False
txt_Direccion.Enabled = False
txt_Telefono.Enabled = False
TxtCedula.Enabled = False
txt_Email.Enabled = False

cmd_Eliminar.Enabled = True
CmdEditar.Visible = True
End If

If nCliente(cbo_Nombre.Text) <> 0 Then

Sheets("Funcionarios").Activate

'Cells(cbo_Nombre.ListIndex + 2, 1).Select
'TxtNombres = cbo_Nombre.Text
'TxtNombres = cbo_Nombre.Text
'txt_Direccion = ActiveCell.Offset(0, 1)
'txt_Telefono = ActiveCell.Offset(0, 2)
'TxtCedula = ActiveCell.Offset(0, 3)
'txt_Email = ActiveCell.Offset(0, 4)
Cells(cbo_Nombre.ListIndex + 2, 1).Select
CmbCategoria = ActiveCell.Offset(0, 2)
CmbGenero = ActiveCell.Offset(0, 3)
CmbCuerpo = ActiveCell.Offset(0, 5)
CmbGrado = ActiveCell.Offset(0, 4)
CmbArma = ActiveCell.Offset(0, -1)
TxtApellidos = ActiveCell.Offset(0, 0)
'TxtNombres = ActiveCell.Offset(0, 1)
'TxtNombres = cbo_Nombre.Text
'txt_Direccion = ActiveCell.Offset(0, 3)
'txt_Telefono = ActiveCell.Offset(0, 4)
'TxtCedula = ActiveCell.Offset(0, 2)
'txt_Email = ActiveCell.Offset(0, 6)

Fotografia.Picture = LoadPicture("")
Fotografia.Picture = LoadPicture(ActiveCell.Offset(0, 7))

ArchivoIMG = ActiveCell.Offset(0, 8)
ArchivoIMG2 = ActiveCell.Offset(0, 9)

Else
CmbCategoria = ""
CmbGenero = ""
CmbCuerpo = ""
CmbGrado = ""
CmbArma = ""
TxtApellidos = ""
TxtNombres = ""
txt_Direccion = ""
txt_Telefono = ""
TxtCedula = ""
txt_Email = ""
ArchivoIMG = ""
ArchivoIMG2 = ""
Fotografia.Picture = LoadPicture("")
End If

'TxtNombres.SetFocus ' RECIBE EL FOCO AL CAMBIAR

End Sub

Con esta macro pretendo colocar en todos los combobox y textbox que tiene el formulario la información que exista sobre la selección, pero no he logrado dar con el "chiste".

Esto hace parte de un pequeño proyecto casero, si alguien tiene la disposición para colaborarme, con gusto le envío el fichero para que vean en que estoy trabajando y de paso me echen una mano.

1 Respuesta

Respuesta
1

Estás seleccionando la celda cuya fila tiene relación con el indice del combobox y la col es A(1)

Cells(cbo_Nombre.ListIndex + 2, 1).Select

Entonces no podés enviar a un control datos a la izquierda de esta selección, como en esta línea:

CmbArma = ActiveCell.Offset(0, -1)

Todos los pases se harán desde la selección, es decir desde la col A.

Si esto resuelve tu consulta no olvides valorarla. Sinó enviame tu libro. Mi correo aparece en la portada de mi sitio.

Gracias por la pronta respuesta Elsa.

Hace unos minutos te envié el fichero al correo que aparece en tu sitio Web.

Nuevamente gracias..!

Tu libro presenta un Userform con alrededor de 100 macros... podrías aclararme cuál es la que no funciona o qué parte del UF debo revisar?

Sdos!

Esta es la macro que no logro que me funcione como necesito:

Private Sub cbo_Nombre_Change()
On Error Resume Next

If CmdEditar <> "" Then
CmdEditar.Visible = True
cmd_Agregar.Visible = False
cmd_Eliminar.Enabled = True
Else
CmdEditar.Visible = False
cmd_Agregar.Visible = True
cmd_Eliminar.Enabled = False
End If

If cbo_Nombre = "" Then
cmd_Eliminar.Enabled = False
CmdEditar.Visible = False
cmd_Agregar.Visible = True
Else
TxtNombres.Enabled = False
txt_Direccion.Enabled = False
Txt_Telefono.Enabled = False
TxtCedula.Enabled = False
txt_Email.Enabled = False

cmd_Eliminar.Enabled = True
CmdEditar.Visible = True
End If

If nCliente(cbo_Nombre.Text) <> 0 Then

'Sheets("Funcionarios").Activate

Cells(cbo_Nombre.ListIndex + 2, 1).Select
'TxtNombres = cbo_Nombre.Text
'TxtNombres = cbo_Nombre.Text
'txt_Direccion = ActiveCell.Offset(0, 1)
'txt_Telefono = ActiveCell.Offset(0, 2)
'TxtCedula = ActiveCell.Offset(0, 3)
'txt_Email = ActiveCell.Offset(0, 4)
Cells(cbo_Nombre.ListIndex + 6, 2).Select
CmbCategoria = ActiveCell.Offset(0, -1)
CmbGenero = ActiveCell.Offset(0, 1)
CmbCuerpo = ActiveCell.Offset(0, 4)
'CmbGrado = ActiveCell.Offset(0, 2)
CmbArma = ActiveCell.Offset(0, 3)
TxtApellidos = ActiveCell.Offset(0, 4)
TxtNombres = ActiveCell.Offset(0, 5)
'TxtNombres = cbo_Nombre.Text
txt_Direccion = ActiveCell.Offset(0, 7)
'txt_Telefono = ActiveCell.Offset(0, 4)
TxtCedula = ActiveCell.Offset(0, 6)
Txt_Telefono = ActiveCell.Offset(0, 6)
TxtTelefax = ActiveCell.Offset(0, 7)
TxtCelular1 = ActiveCell.Offset(0, 8)
TxtCelular2 = ActiveCell.Offset(0, 9)
txt_Email = ActiveCell.Offset(0, 10)
TxtEmail2 = ActiveCell.Offset(0, 11)

'Fotografia.Picture = LoadPicture("")
'Fotografia.Picture = LoadPicture(ActiveCell.Offset(0, 7))

'ArchivoIMG = ActiveCell.Offset(0, 8)
'ArchivoIMG2 = ActiveCell.Offset(0, 9)

Else
CmbCategoria = ""
CmbGenero = ""
CmbCuerpo = ""
CmbGrado = ""
CmbArma = ""
TxtApellidos = ""
TxtNombres = ""
txt_Direccion = ""
Txt_Telefono = ""
TxtCedula = ""
txt_Email = ""
ArchivoIMG = ""
ArchivoIMG2 = ""
Fotografia.Picture = LoadPicture("")
End If

'TxtNombres.SetFocus ' RECIBE EL FOCO AL CAMBIAR

End Sub

Específicamente esta parte:

Cells(cbo_Nombre.ListIndex + 2, 1).Select
CmbCategoria = ActiveCell.Offset(0, -1)
CmbGenero = ActiveCell.Offset(0, 1)
CmbCuerpo = ActiveCell.Offset(0, 4)
'CmbGrado = ActiveCell.Offset(0, 2)
CmbArma = ActiveCell.Offset(0, 3)
TxtApellidos = ActiveCell.Offset(0, 4)
TxtNombres = ActiveCell.Offset(0, 5)
'TxtNombres = cbo_Nombre.Text
txt_Direccion = ActiveCell.Offset(0, 7)
'txt_Telefono = ActiveCell.Offset(0, 4)
TxtCedula = ActiveCell.Offset(0, 6)
Txt_Telefono = ActiveCell.Offset(0, 6)
TxtTelefax = ActiveCell.Offset(0, 7)
TxtCelular1 = ActiveCell.Offset(0, 8)
TxtCelular2 = ActiveCell.Offset(0, 9)
txt_Email = ActiveCell.Offset(0, 10)
TxtEmail2 = ActiveCell.Offset(0, 11)

'Fotografia.Picture = LoadPicture("")
'Fotografia.Picture = LoadPicture(ActiveCell.Offset(0, 7))

'ArchivoIMG = ActiveCell.Offset(0, 8)
'ArchivoIMG2 = ActiveCell.Offset(0, 9)

Gracias Elsa.

Te envío el libro ajustado. Te estabas posicionando en otra hoja al cargar uno de los combos. Además tenías otros errores de ubicación de datos, como género y cuerpo.

Sdos!

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas