Excel VBA中的搜索框

时间:2017-07-24 12:59:39

标签: excel vba excel-vba excel-formula

我的代码有一个简单的问题。事情是我的搜索框工作我可以搜索我的数据到另一张表但问题是我需要在字段上键入相同的文本。就像数据是用大写锁定写的一样,我也需要用大写锁定它。我不喜欢那样。我想禁用区分大小写但如何?你可以帮帮我吗这是我的代码截图。

screenshot

这是我的代码

Sub searchData()
Dim erow As Long 
Dim ws As Worksheet
Dim lastrow As Long
Dim count As Integer
Dim mySearch As Variant
Dim SearchString As String

    mySearch = Sheets("Control").Range("B2").Value 'Cell Input
    lastrow = Sheets("Data").Cells(Rows.count, 3).End(xlUp).Row

    For x = 2 To lastrow

    If Sheets("Data").Cells(x, 3) = mySearch Then
    'Loan Details
        Sheets("Control").Range("B4") = Sheets("Data").Cells(x, 1)
        Sheets("Control").Range("B5") = Sheets("Data").Cells(x, 2)
        Sheets("Control").Range("B6") = Sheets("Data").Cells(x, 3)
        Sheets("Control").Range("B7") = Sheets("Data").Cells(x, 4)
        Sheets("Control").Range("B8") = Sheets("Data").Cells(x, 5)
        Sheets("Control").Range("B9") = Sheets("Data").Cells(x, 6)
        Sheets("Control").Range("B10") = Sheets("Data").Cells(x, 7)
        Sheets("Control").Range("B11") = Sheets("Data").Cells(x, 8)
        Sheets("Control").Range("B12") = Sheets("Data").Cells(x, 9)
        Sheets("Control").Range("B13") = Sheets("Data").Cells(x, 10)
        Sheets("Control").Range("B14") = Sheets("Data").Cells(x, 11)
    'Personal Details
        Sheets("Control").Range("B15") = Sheets("Data").Cells(x, 12)
        Sheets("Control").Range("B16") = Sheets("Data").Cells(x, 13)
        Sheets("Control").Range("B17") = Sheets("Data").Cells(x, 14)
        Sheets("Control").Range("B18") = Sheets("Data").Cells(x, 15)
        Sheets("Control").Range("B19") = Sheets("Data").Cells(x, 16)
        Sheets("Control").Range("B20") = Sheets("Data").Cells(x, 17)
        Sheets("Control").Range("B21") = Sheets("Data").Cells(x, 18)
        Sheets("Control").Range("B22") = Sheets("Data").Cells(x, 19)
        Sheets("Control").Range("B23") = Sheets("Data").Cells(x, 20)
        Sheets("Control").Range("B24") = Sheets("Data").Cells(x, 21)
        Sheets("Control").Range("B25") = Sheets("Data").Cells(x, 22)
        Sheets("Control").Range("B26") = Sheets("Data").Cells(x, 23)
        Sheets("Control").Range("B27") = Sheets("Data").Cells(x, 24)
        Sheets("Control").Range("B28") = Sheets("Data").Cells(x, 25)
        Sheets("Control").Range("B29") = Sheets("Data").Cells(x, 26)
        Sheets("Control").Range("B30") = Sheets("Data").Cells(x, 27)
    'Employment Details
        Sheets("Control").Range("B31") = Sheets("Data").Cells(x, 28)
        Sheets("Control").Range("B32") = Sheets("Data").Cells(x, 29)
        Sheets("Control").Range("B33") = Sheets("Data").Cells(x, 30)
        Sheets("Control").Range("B34") = Sheets("Data").Cells(x, 31)
        Sheets("Control").Range("B35") = Sheets("Data").Cells(x, 32)
        Sheets("Control").Range("B36") = Sheets("Data").Cells(x, 33)


    End If

Next x

End Sub

1 个答案:

答案 0 :(得分:0)

将If条件更改为如下所示,无论您输入的是什么,都会自动搜索大写文本

UCase(Sheets("Data").Cells(x,3)) = UCase(mySearch)

例如: 在Sheet中你有="样本"在搜索框中输入了"样本 搜索将搜索" SAMPLE = SAMPLE"