Jump to content
Fórum Script Brasil
  • 0

Problemas com textbox não preenchida.


Question

Estou com um problema no código que quando dou ENTER em uma textbox vazia ele redireciona-me para o código com uma mensagem de erro, como eu posso fazer para ele não me redirecionar para o código, e mandar uma mensagebox com uma mensagem de erro.

Option Explicit

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    If KeyCode = 13 Then Call Filtro(TextBox1.Text, ComboBox1.Text)
End Sub

Private Sub TextBox2_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    If KeyCode = 13 Then Call Filtro(TextBox2.Text, ComboBox2.Text)
End Sub

Private Sub TextBox3_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    If KeyCode = 13 Then Call Filtro(TextBox3.Text, ComboBox3.Text)
End Sub

Private Sub UserForm_Initialize()
    ComboBox1.RowSource = "Relatório!C1:C11"
    ComboBox2.RowSource = "Relatório!C1:C11"
    ComboBox3.RowSource = "Relatório!C1:C11"
End Sub

Sub Filtro(ByVal Pesquisar_Imo As String, Campo As String)
    Dim Coluna  As Integer
    Dim Area    As Range
    
    Set Area = ThisWorkbook.Sheets("Dados_Imobilizado").[A1:K1]
    Coluna = WorksheetFunction.Match(Campo, Area, 0)
    If Pesquisar_Imo <> "" Then
        If IsNumeric(Pesquisar_Imo) = False Then Pesquisar_Imo = "*" & Pesquisar_Imo & "*"
        Call Area.AutoFilter(Field:=Coluna, Criteria1:=Pesquisar_Imo)
        Call CopiaTabela
        Call PreencheListBox
    End If
End Sub

Sub CopiaTabela()
    ThisWorkbook.Sheets("Auxiliar").[N:X].Clear
    ThisWorkbook.Sheets("Dados_Imobilizado").[A1].CurrentRegion.Copy
    ThisWorkbook.Sheets("Auxiliar").[N1].PasteSpecial xlPasteValues
    Application.CutCopyMode = False
End Sub

Sub PreencheListBox()
    Dim Area    As Range
    Set Area = ThisWorkbook.Sheets("Auxiliar").[N1].CurrentRegion
    ListBox1.ColumnCount = Area.Columns.Count
    ListBox1.ColumnHeads = True
    ListBox1.RowSource = "Auxiliar!" & Area.Offset(1).Address
End Sub

Link do programa: 

https://drive.google.com/file/d/1WTRoJ_4EzZGMsuYPkUoKNjbgCYEIO2TB/view?usp=sharing

 

Captura de ecrã 2021-03-24 135441.png

Captura de ecrã 2021-03-24 135423.png

Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      149411
    • Total Posts
      645902
×
×
  • Create New...