Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 使用Match返回列号_Vba_Excel - Fatal编程技术网

Vba 使用Match返回列号

Vba 使用Match返回列号,vba,excel,Vba,Excel,正在尝试使用.Match标识要搜索行的列值 基本上,我有3个工作表,每个工作表都有不同的标题,为了比较数据,我想确定每个工作表中哪些标题是相同的 这是我目前掌握的代码,目前只是一个PoC: Sub aaaa() Dim a As Double Dim b As Integer Dim c As Integer Dim d As Variant Dim e As Variant Dim f As Variant Dim h As Double Worksheets("Reconciliatio

正在尝试使用.Match标识要搜索行的列值

基本上,我有3个工作表,每个工作表都有不同的标题,为了比较数据,我想确定每个工作表中哪些标题是相同的

这是我目前掌握的代码,目前只是一个PoC:

Sub aaaa()

Dim a As Double
Dim b As Integer
Dim c As Integer
Dim d As Variant
Dim e As Variant
Dim f As Variant
Dim h As Double

Worksheets("Reconciliation").Activate

Columns.Select
Selection.ClearContents

a = 1
h = 2

While Worksheets("Cleanse").Cells(a, 1) <> vbNullString

    b = 1
    c = 1
    d = vbNullString
    e = vbNullString
    f = vbNullString

    While Worksheets("Cleanse").Cells(a, 1) <> vbNullString

        If a = 1 Then
            Cells(h, b) = Worksheets("Cleanse").Cells(a, c)
            Cells(h, b + 1) = Worksheets("Cleanse").Cells(a, c) & "_CUMIS"

            d = WorksheetFunction.Match(Worksheets("Cleanse").Cells(a, c), Worksheets("MAddress").Rows("1:1"), 0)

            If Not IsError(d) Then

                Cells(h - 1, b + 1) = d

            ElseIf IsError(d) Then

                d = WorksheetFunction.Match(Worksheets("Cleanse").Cells(a, c), Worksheets("Member_Details").Rows(1), 0)
                Cells(h - 1, b + 1) = "M" & d

            End If

            b = b + 2
            c = c + 1

        Else
            Cells(h, b) = Worksheets("Cleanse").Cells(a, c)

            If b = 1 Then
                e = WorksheetFunction.Match(Worksheets("Cleanse").Cells(a, c), Worksheets("MAddress").Range("A:A"), 0)


                If Not IsError(e) And Not IsError(d) Then

                    Cells(a, b + 1) = Worksheets("MAddress").Cells(d, e)

                Else
                End If
            End If



        End If

    Wend

    a = a + 1

Wend

End Sub

关于如何在行中搜索变量值并返回列号的任何建议>

如果要使用iErrord测试d,则必须使用d=application.match…,而不是d=worksheetFunction.match

        d = Application.Match(Worksheets("Cleanse").Cells(a, c), Worksheets("MAddress").Rows("1:1"), 0)

        If Not IsError(d) Then
            Cells(h - 1, b + 1) = d
        Else
            d = Application.Match(Worksheets("Cleanse").Cells(a, c), Worksheets("Member_Details").Rows(1), 0)
            If Not IsError(d) Then
                Cells(h - 1, b + 1) = "M" & d
            end if
        End If
        ...

您可以使用Find函数,请详细说明一下好吗?哪一行生成运行时错误“9”:Subscription out of Range=Worksheetfunction.match…更改后仍返回相同的错误那么您有多个问题。WorksheetFunction不会生成可使用iError测试的结果。请认为问题出在行上使用的.Match周围。关于如何解决这个问题有什么想法吗?没有,我一直在使用类似的代码。您是否也将e匹配项更改为application.match/
        d = Application.Match(Worksheets("Cleanse").Cells(a, c), Worksheets("MAddress").Rows("1:1"), 0)

        If Not IsError(d) Then
            Cells(h - 1, b + 1) = d
        Else
            d = Application.Match(Worksheets("Cleanse").Cells(a, c), Worksheets("Member_Details").Rows(1), 0)
            If Not IsError(d) Then
                Cells(h - 1, b + 1) = "M" & d
            end if
        End If
        ...