excel vba代码在列中查找值很慢,如何让它更快?

时间:2015-05-14 21:21:22

标签: excel vba find range offset

下面的我的vba代码,它如何更快? (obs:我有+ - 33000行值) 我搜索从产品到我公司的代码,我需要帮助才能更快地完成。

Private Sub TextBox1_Enter()
Dim FindString As String
Dim Rng As Range
FindString = TextBox1.Text
If Trim(FindString) <> "" And Len(TextBox1.Text) = 6 Then
   With Sheets("CADMAT").Range("B:B") 'searches all of column B
        Set Rng = .Find(What:=FindString, _
                    After:=.Cells(.Cells.Count), _
                    LookIn:=xlValues, _
                    LookAt:=xlWhole, _
                    SearchOrder:=xlByRows, _
                    SearchDirection:=xlNext, _
                    MatchCase:=False)
    If Not Rng Is Nothing Then
        Dim ultimalinha As Object
        Set ultimalinha = Plan3.Range("A35565").End(xlUp)
        ultimalinha.Offset(1, 0).Value = TextBox1.Text
        ultimalinha.Offset(1, 1).Value = TextBox2.Text
        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox1.SetFocus
    Else
        MsgBox "Produto não existe na tabela!" 'value not found
        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox1.SetFocus
    End If
End With
End If
End Sub

1 个答案:

答案 0 :(得分:0)

选项明确

Private Sub TextBox1_Enter()

Application.ScreenUpdating = False

这里的代码......

Application.ScreenUpdating = True

End Sub