Erro VLOOKUP em Userform
Enviado: 09 Mai 2016 às 14:04
Boa tarde pessoal,
Estou fazendo uma planilha para gerenciar a manutenção de algumas maquinas e enfrento um problema que, quando abro o Userform2 o Label4 deveria ser preenchido com o valor resultante da formula contida em ListBox1, para ser usado no CommandBotton1. mas a formula retorna com um erro. o código está abaixo. A planilha está em anexo. vejam se há algo errado.
Private Sub CommandButton1_Click()
Dim estado, obs
estado = ListBox1
obs = ListBox2
linha = Label4
Worksheets("ESTADO").Range("E" & linha).Value = ListBox1.Text
Worksheets("ESTADO").Range("F" & linha).Value = TextBox2.Text
lin = 5
col = 1
col2 = 5
col3 = 6
col4 = 7
col5 = 2
col6 = 3
col7 = 4
While Sheets("DIARIO").Cells(lin, col) <> ""
lin = lin + 1
Wend
Sheets("DIARIO").Cells(lin, col) = TextBox1.Value
Sheets("DIARIO").Cells(lin, col2) = ListBox1.Value
Sheets("DIARIO").Cells(lin, col3) = TextBox2.Value
Sheets("DIARIO").Cells(lin, col5) = UserForm1.txt_serial
Sheets("DIARIO").Cells(lin, col6) = UserForm1.txt_modelo
Sheets("DIARIO").Cells(lin, col7) = UserForm1.txt_fabricante
Sheets("DIARIO").Cells(lin, col4) = Date
Unload UserForm2
End Sub
Private Sub ListBox1_Change()
If ListBox1 = "PRONTA" Then
TextBox1.BackColor = &HC000&
TextBox2.BackColor = &HC000&
TextBox1.ForeColor = &H0&
TextBox2.ForeColor = &H0&
Else
If ListBox1 = "PENDENTE DE PEÇAS" Then
TextBox1.BackColor = &HFF&
TextBox2.BackColor = &HFF&
TextBox1.ForeColor = &H80000005
TextBox2.ForeColor = &H80000005
Else
If ListBox1 = "DESCARTADA" Then
TextBox1.BackColor = &H80FF&
TextBox2.BackColor = &H80FF&
TextBox1.ForeColor = &H0&
TextBox2.ForeColor = &H0&
Else
If ListBox1 = "DESMONTAGEM" Then
TextBox1.BackColor = &HFFFF&
TextBox2.BackColor = &HFFFF&
TextBox1.ForeColor = &H0&
TextBox2.ForeColor = &H0&
End If
End If
End If
End If
Dim intervalo As Range
Dim texto As String
Dim toner As Integer
Dim pequisar
Dim mensagem
toner = TextBox1
Sheets("ESTADO").Select
Set intervalo = Range("A4:F20000")
On Error GoTo trataErro
pesquisar = Application.WorksheetFunction.VLookup(toner, intervalo, 7, False)
Label4 = pesquisar
Exit Sub
trataErro:
texto = "equipamento não localizado!"
mensagem = MsgBox(texto, vbOKOnly + vbInformation)
End Sub
Private Sub TextBox2_Change()
TextBox2.Text = UCase(TextBox2.Text)
End Sub
Private Sub UserForm_Initialize()
UserForm2.TextBox1 = UserForm1.txt_serial
End Sub
Estou fazendo uma planilha para gerenciar a manutenção de algumas maquinas e enfrento um problema que, quando abro o Userform2 o Label4 deveria ser preenchido com o valor resultante da formula contida em ListBox1, para ser usado no CommandBotton1. mas a formula retorna com um erro. o código está abaixo. A planilha está em anexo. vejam se há algo errado.
Private Sub CommandButton1_Click()
Dim estado, obs
estado = ListBox1
obs = ListBox2
linha = Label4
Worksheets("ESTADO").Range("E" & linha).Value = ListBox1.Text
Worksheets("ESTADO").Range("F" & linha).Value = TextBox2.Text
lin = 5
col = 1
col2 = 5
col3 = 6
col4 = 7
col5 = 2
col6 = 3
col7 = 4
While Sheets("DIARIO").Cells(lin, col) <> ""
lin = lin + 1
Wend
Sheets("DIARIO").Cells(lin, col) = TextBox1.Value
Sheets("DIARIO").Cells(lin, col2) = ListBox1.Value
Sheets("DIARIO").Cells(lin, col3) = TextBox2.Value
Sheets("DIARIO").Cells(lin, col5) = UserForm1.txt_serial
Sheets("DIARIO").Cells(lin, col6) = UserForm1.txt_modelo
Sheets("DIARIO").Cells(lin, col7) = UserForm1.txt_fabricante
Sheets("DIARIO").Cells(lin, col4) = Date
Unload UserForm2
End Sub
Private Sub ListBox1_Change()
If ListBox1 = "PRONTA" Then
TextBox1.BackColor = &HC000&
TextBox2.BackColor = &HC000&
TextBox1.ForeColor = &H0&
TextBox2.ForeColor = &H0&
Else
If ListBox1 = "PENDENTE DE PEÇAS" Then
TextBox1.BackColor = &HFF&
TextBox2.BackColor = &HFF&
TextBox1.ForeColor = &H80000005
TextBox2.ForeColor = &H80000005
Else
If ListBox1 = "DESCARTADA" Then
TextBox1.BackColor = &H80FF&
TextBox2.BackColor = &H80FF&
TextBox1.ForeColor = &H0&
TextBox2.ForeColor = &H0&
Else
If ListBox1 = "DESMONTAGEM" Then
TextBox1.BackColor = &HFFFF&
TextBox2.BackColor = &HFFFF&
TextBox1.ForeColor = &H0&
TextBox2.ForeColor = &H0&
End If
End If
End If
End If
Dim intervalo As Range
Dim texto As String
Dim toner As Integer
Dim pequisar
Dim mensagem
toner = TextBox1
Sheets("ESTADO").Select
Set intervalo = Range("A4:F20000")
On Error GoTo trataErro
pesquisar = Application.WorksheetFunction.VLookup(toner, intervalo, 7, False)
Label4 = pesquisar
Exit Sub
trataErro:
texto = "equipamento não localizado!"
mensagem = MsgBox(texto, vbOKOnly + vbInformation)
End Sub
Private Sub TextBox2_Change()
TextBox2.Text = UCase(TextBox2.Text)
End Sub
Private Sub UserForm_Initialize()
UserForm2.TextBox1 = UserForm1.txt_serial
End Sub