excel vba用户形式搜索

时间:2016-10-05 10:51:35

标签: excel vba excel-vba userform

我需要一些关于搜索功能的帮助,如何转换此用户窗体将搜索我的工作簿的其他工作表

其他工作表的名称是“DataSource”

我计划将数据分成另一张工作簿,然后定义一个名称,我会将其作为偏移量,所以每当我输入另一个数据时,它将能够使用我的搜索用户形式进行搜索

这是我的代码

Sub GetData()
Dim id As Integer, i As Integer, j As Integer, flag As Boolean

If IsNumeric(UserForm1.TextBox1.Value) Then
    flag = False
    i = 0
    id = UserForm1.TextBox1.Value

    Do While Cells(i + 1, 1).Value <> ""

        If Cells(i + 1, 1).Value = id Then
            flag = True
            For j = 2 To 3
                UserForm1.Controls("TextBox" & j).Value = Cells(i + 1, j).Value
            Next j
        End If

        i = i + 1

    Loop

    If flag = False Then
        For j = 2 To 3
            UserForm1.Controls("TextBox" & j).Value = ""
        Next j
    End If

Else
    ClearForm
End If

End Sub

这是我编辑数据的代码

Sub EditAdd()

Dim emptyRow As Long

If UserForm1.TextBox1.Value <> "" Then
    flag = False
    i = 0
    id = UserForm1.TextBox1.Value
    emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1

    Do While Cells(i + 1, 1).Value <> ""

        If Cells(i + 1, 1).Value = id Then
            flag = True
            For j = 2 To 3
                Cells(i + 1, j).Value = UserForm1.Controls("TextBox" & j).Value
            Next j
        End If

        i = i + 1

    Loop

    If flag = False Then
        For j = 1 To 3
            Cells(emptyRow, j).Value = UserForm1.Controls("TextBox" & j).Value
        Next j
    End If

End If

End Sub

这是数据源表的定义名称

名称:数据

=OFFSET(DataSource!$A:$A,1,0,COUNTA(DataSource!$A:$A)-1,1)

0 个答案:

没有答案
相关问题