Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.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 如何使用循环匹配图纸之间的数据_Vba_Excel - Fatal编程技术网

Vba 如何使用循环匹配图纸之间的数据

Vba 如何使用循环匹配图纸之间的数据,vba,excel,Vba,Excel,好吧,那就崩溃吧 我有两张床单。一张工作表(order_LVL)包含原始数据,其中订单号沿行向下,而“行号”包含相应单元格中该行的整数位置。我试图用相同的订单号沿着行向下填充另一张表(sheet1),但位置号(1-246)作为列标题(基本上,order_LVL单元格中的值正在成为sheet1的列标题)。在相应的单元格中,如果订单_LVL表示订单包含来自该位置的一行,则我想输入一个“1”,如果没有,则输入一个“0” 这就是我用来填充数据的方法,我一直在If语句的行中得到一个错误,说“object不

好吧,那就崩溃吧

我有两张床单。一张工作表(order_LVL)包含原始数据,其中订单号沿行向下,而“行号”包含相应单元格中该行的整数位置。我试图用相同的订单号沿着行向下填充另一张表(sheet1),但位置号(1-246)作为列标题(基本上,order_LVL单元格中的值正在成为sheet1的列标题)。在相应的单元格中,如果订单_LVL表示订单包含来自该位置的一行,则我想输入一个“1”,如果没有,则输入一个“0”

这就是我用来填充数据的方法,我一直在If语句的行中得到一个错误,说“object不支持这个属性或方法”


我是VBA新手,希望您提供帮助指导。

请尝试下面修复的代码。请原谅,我没有阅读业务上下文(有点匆忙),只是修复了脚本中的语法问题

Sub PopulateData()
Dim s1 As Worksheet
Dim s2 As Worksheet
Dim locationRow As Integer
Set s1 = Sheets("Order_LVL")
Set s2 = Sheets("sheet1")
Dim orderrows As Range
Dim Lastrow As Integer
Lastrow = s1.Cells(Rows.Count, 1).End(xlUp).Row
Set orderrows = Range("B2" & Lastrow)
Dim iRow As Integer

For iRow = 1 To orderrows.Rows.Count
Dim cellj As Range
    For Each cellj In s1.Range("Q:DL")
    locationRow = 1
    Dim celli As Range
        For Each celli In s2.Range("B1:JE1")
            If s1.Cells(iRow, cellj.Column).Value = s2.Cells(locationRow, celli.Column).Value Then
            s2.Cells(iRow, celli.Column).Value = 1 'indicates that this order features a line from this location
            Else: s2.Cells(iRow, celli).Value = 0
            End If
        Next celli
    Next cellj
Next iRow
End Sub

j循环将按顺序遍历当前iRow中的每个单元格,i循环将遍历sheet1中的位置标题,以与Order\U LVL工作表中单元格的值相匹配。与
SheetVariable(Row,Column)
不同,您需要像这样调用cells方法:
SheetVariable.cells(Row,Column)
好的,现在我在同一行得到一个错误,说“类型不匹配”“我想这可能是因为我的I、j和iRow是变体,但我不知道还能做些什么。”。我认为它们应该是for-Each循环的变体。按照循环的结构,它的效率非常低。相反,请考虑:
对于i=2到orderrows
对于j=2到Columns(“JE”)。Column
您可以编辑您的问题以包括一些样本数据和预期结果吗?没问题……只需注意这一行
其他:s2.单元格(iRow,celli)。Value=0应该是
其他:s2.单元格(iRow,celli.Column)。Value=0
Sub PopulateData()
Dim s1 As Worksheet
Dim s2 As Worksheet
Dim locationRow As Integer
Set s1 = Sheets("Order_LVL")
Set s2 = Sheets("sheet1")
Dim orderrows As Range
Dim Lastrow As Integer
Lastrow = s1.Cells(Rows.Count, 1).End(xlUp).Row
Set orderrows = Range("B2" & Lastrow)
Dim iRow As Integer

For iRow = 1 To orderrows.Rows.Count
Dim cellj As Range
    For Each cellj In s1.Range("Q:DL")
    locationRow = 1
    Dim celli As Range
        For Each celli In s2.Range("B1:JE1")
            If s1.Cells(iRow, cellj.Column).Value = s2.Cells(locationRow, celli.Column).Value Then
            s2.Cells(iRow, celli.Column).Value = 1 'indicates that this order features a line from this location
            Else: s2.Cells(iRow, celli).Value = 0
            End If
        Next celli
    Next cellj
Next iRow
End Sub