Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.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
Excel 不匹配错误/代码不工作_Excel_Vba - Fatal编程技术网

Excel 不匹配错误/代码不工作

Excel 不匹配错误/代码不工作,excel,vba,Excel,Vba,这是更新的代码。我现在得到一个不匹配错误。如果有人能提供一些帮助,那就太好了。提前谢谢 Sub Macro2() Dim rowcount As Long Dim target As Variant, startcell4 As Range Set startcell4 = ActiveSheet.Cells(2, 1) rowcount = Range(Range("E2"), Range("E2").End(xlDown)).Rows.Count For i = 2 To rowc

这是更新的代码。我现在得到一个不匹配错误。如果有人能提供一些帮助,那就太好了。提前谢谢

Sub Macro2()

Dim rowcount As Long

Dim target As Variant, startcell4 As Range

Set startcell4 = ActiveSheet.Cells(2, 1)

rowcount = Range(Range("E2"), Range("E2").End(xlDown)).Rows.Count

For i = 2 To rowcount + 1

    If Not ActiveSheet.Cells(i, 26) = ActiveSheet.Cells(i + 1, 26) Then

    Set target = Application.Match(ActiveSheet.Cells(i, 26), Worksheets(19).Range("A6:A3000"), 0)


        If Not IsError(target) Then

        ActiveSheet.startcell4.Offset(0, 17).Value = Worksheets(19).Cells(target + 6, 10)

        Set startcell4 = ActiveSheet.Cells(i + 1, 26)

        End If

    End If

Next i

End Sub
更改:

  • “将目标=…”设置为“目标=…”

  • “ActiveSheet.startcell4”到“startcell4”

  • 一点重构

说到这里

Sub Macro2()
    Dim rowcount As Long
    Dim target As Variant, startcell4 As Range

    Set startcell4 = Cells(2, 1)
    rowcount = Range("E2").End(xlDown).Row
    For i = 2 To rowcount
        If Not Cells(i, 26) = Cells(i + 1, 26) Then
            target = Application.Match(Cells(i, 26), Worksheets(19).Range("A6:A3000"), 0)
            If Not IsError(target) Then
                startcell4.Offset(0, 17).Value = Worksheets(19).Cells(target + 6, 10)
                Set startcell4 = Cells(i + 1, 26)
            End If
        End If
    Next i
End Sub

match函数
将返回范围内的行数(“A6:A3000”),其中可以找到ActiveSheet.Cells(i,26)的值。例如,如果可以在单元格A9中找到单元格(i,26),则match函数将返回值3,因为它是范围内的第三个值(“A6:A3000”)。我根据您所说的进行了更新,但仍然没有得到输出。请将“Set target=…”更改为“target=…”