Inquiridor
Adicionar cabeçalho no ListBox1

Pergunta
-
Boa noite.
Galera estou desenvolvendo uma planilha para gerenciar os acionamentos que outras áreas da empresas realisa para minha equipe.
a planilha funciona da seguinte maneira:
tenho uma planilha fixa no excel, criei um botão que chama uma ListBox1 com todas as informações da planilha quando quero buscar um chamado especifico digito o número do chamado em um campo de busca que me traz com todas as informações.
o problema é que não estou conseguido inserir o cabeçalho de cada coluna algum pode me ajudar?
FORM:
Private Sub CommandButton1_Click()
'seleciona a primeira celula da planilha
Range("A1").Select
'poe o foco no TextBox1
TextBox1.SetFocus
'define duas variáveis para tratar a linha atual e o contador
Dim linhaAtual As Integer
Dim contador As Integer
'verifica se o TextBox1 é diferente (<>) de vazio
If TextBox1.Text <> "" Then
'atribui o valor zero ao contador
contador = 0
'inicia um laço While verificando se o valor da célula é diferente do
'TextBox1 e se o contador é menor que 20. Enquanto isso for verdade o
'laço irá ser executado
Do While ActiveCell.Value <> TextBox1.Text And contador < 20
ActiveCell.Offset(1, 0).Select
contador = contador + 1
Loop
End If
'compara ambos os valores convertidos para maiusculas
'If UCase(ActiveCell.Value) = UCase(TextBox1.Value) Then
If ActiveCell.Value = TextBox1.Value Then
'limpa o listbox
ListBox1.Clear
'atribuir o valor da célula ativa à linhaAtual
linhaAtual = ActiveCell.Row
'inclui o valor da linha atual no listbox
ListBox1.AddItem Plan1.Range("c" & linhaAtual)
ListBox1.List(ListBox1.ListCount - 1, 2) = Plan1.Range("D" & linhaAtual)
ListBox1.List(ListBox1.ListCount - 1, 3) = Plan1.Range("E" & linhaAtual)
ListBox1.List(ListBox1.ListCount - 1, 4) = Plan1.Range("I" & linhaAtual)
ListBox1.List(ListBox1.ListCount - 1, 5) = Plan1.Range("J" & linhaAtual)
ListBox1.List(ListBox1.ListCount - 1, 6) = Plan1.Range("K" & linhaAtual)
ListBox1.List(ListBox1.ListCount - 1, 7) = Plan1.Range("L" & linhaAtual)
ListBox1.List(ListBox1.ListCount - 1, 8) = Plan1.Range("N" & linhaAtual)
ListBox1.List(ListBox1.ListCount - 1, 9) = Plan1.Range("O" & linhaAtual)
Else
'o registro não foi encontrado
MsgBox "Registro não encontrado", vbCritical, "Erro"
TextBox1.SetFocus
End If
End Sub
Private Sub CommandButton2_Click()
'limpa o listbox
ListBox1.Clear
'limpa o textbox
TextBox1.Text = ""
'atribui o foco ao textbox
TextBox1.SetFocus
'chama a macro preencherListBox
Call preencherListBox
End Sub
Private Sub Image1_Click()
Sub Imagem_na_Planilha()
Dim Plan As Worksheet, Imagem As Shape
Set Plan = ActiveSheet
Set Imagem = Plan.Shapes.AddPicture("desktop:\teste", msoFalse, msoCTrue, 50, 50, 70, 70)
End Sub
Private Sub Label1_Click()
End Sub
Private Sub ListBox1_Click()
End Sub
Private Sub TextBox1_Change()
End Sub
Private Sub UserForm_Initialize()
'preenche o listbox
Call preencherListBox
End SubMódulo
Sub preencherListBox()
Dim ultimaLinha As Long
Dim linha As Integer
'retorna o valor da ultima linha preenchida da coluna
ultimaLinha = Plan1.Range("A90").End(xlUp).Row
'percorre a partir da linha 2 até a ultima linha
For linha = 2 To ultimaLinha
UserForm1.ListBox1.AddItem Plan1.Range("C" & linha)
UserForm1.ListBox1.List(UserForm1.ListBox1.ListCount - 1, 2) = Plan1.Range("D" & linha)
UserForm1.ListBox1.List(UserForm1.ListBox1.ListCount - 1, 3) = Plan1.Range("E" & linha)
UserForm1.ListBox1.List(UserForm1.ListBox1.ListCount - 1, 4) = Plan1.Range("I" & linha)
UserForm1.ListBox1.List(UserForm1.ListBox1.ListCount - 1, 5) = Plan1.Range("J" & linha)
UserForm1.ListBox1.List(UserForm1.ListBox1.ListCount - 1, 6) = Plan1.Range("K" & linha)
UserForm1.ListBox1.List(UserForm1.ListBox1.ListCount - 1, 7) = Plan1.Range("L" & linha)
UserForm1.ListBox1.List(UserForm1.ListBox1.ListCount - 1, 8) = Plan1.Range("N" & linha)
UserForm1.ListBox1.List(UserForm1.ListBox1.ListCount - 1, 9) = Plan1.Range("O" & linha)
Next
End Sub
Sub chamarFormulario()
'abre o formulário UserFomr1
UserForm1.Show
End Sub
- Movido Thales F Quintas sexta-feira, 26 de agosto de 2016 12:03