我试图将一张工作表上的两列数据重新排列成另一张工作表上的行,由第一张工作表上的一列控制。
我正在检查代码,使用 F8 命令对其进行调试,最后遇到了循环命令的问题。我收到了一个“Loop without Do”编译错误,最后用 Excel 突出显示了“Loop until”。
这是它应该做的:
“JCX”(10,AttributeRowCounter)单元格和“08-Attribute”(1,AttributeRowCounter)应该匹配,并控制“08-Attribute”(11,AttributeRowCounter)值在“JCX”中的哪一行。
“08-Attribute”(9,AttributeRowCounter) 值控制“JCX”中的哪一列放置“08-Attribute”(11,AttributeRowCounter) 值。
如果“08-Attribute”(1,AttributeRowCounter)中有一个名为AHU-2的值列表,“08-Attribute”(9,AttributeRowCounter)中对应的值列表为“CFM、EAT、LAT、RPM和SP ”,那么“08-Attribute”(11,AttributeRowCounter) 中的值和(9,AttributeRowCounter) 中的CFM 进入“JCX”(14,TagNumberRow)。
"08-Attribute" (11,AttributeRowCounter) 中的值和 (9,AttributeRowCounter) 中的 RPM 进入 "JCX" (16,TagNumberRow)。
"08-Attribute" (11,AttributeRowCounter) 中的值和 (9,AttributeRowCounter) 中的 SP 进入 "JCX" (15,TagNumberRow)。
如果“08-Attribute”(11,AttributeRowCounter) 中的值在(9,AttributeRowCounter) 中具有除“CFM、SP、RPM 和Motor HP”之外的其他值,则(11,AttributeRowCounter) 中的值进入"JCX" (21,TagNumberRow) 和 (9,AttributeRowCounter) 中的值进入 "JCX" (20,TagNumberRow)。
前面的语句循环,将任何额外的非“CFM、SP、RPM 和电机 HP”值加载到右侧的下一列,根据需要跳过(名称 1、值 1、名称 2、值 2、名称 3、值 3 等)。
有人知道这是怎么回事吗?
'Tag Values
Do
With Sheets("08-Attribute")
Copy.Range("9,AttributeRowCounter").Value
Application.WorksheetFunction.VLookup((Sheets("JCX").Cells(10, AttributeRowCounter)), (Sheets("08-Attribute").Cells(1, AttributeRowCounter)), True).Value
With Sheets("08-Attribute")
If "9,AttributeRowCounter" = "CFM" Then
.Range("11,AttributeRowCounter").Value = Sheets("JCX").Range("14,TagNumberRow").Value
ElseIf "9" = "SP" Then
.Range("11,AttributeRowCounter").Value = Sheets("JCX").Range("15,TagNumberRow").Value
ElseIf "9" = "RPM" Then
.Range("11,AttributeRowCounter").Value = Sheets("JCX").Range("16,TagNumberRow").Value
ElseIf "9" = "Motor_HP" Then
.Range("11,AttributeRowCounter").Value = Sheets("JCX").Range("17,TagNumberRow").Value
Else
.Range("9,AttributeRowCounter").Value = Sheets("JCX").Range("20,TagNumberRow").Value
TagValueNameColumn = TagValueNameColumn + 2
.Range("11,AttributeRowCounter").Value = Sheets("JCX").Range("21,TagNumberRow").Value
TagValueNameColumn = TagValueNameColumn + 2
Loop Until Cells(1, AttributeRowCounter) = False
如果你缩进,问题就会变得更清楚。
Do
With Sheets("08-Attribute")
copy.Range("9,AttributeRowCounter").Value
Application.WorksheetFunction.VLookup((Sheets("JCX").Cells(10, attributerowcounter)), (Sheets("08-Attribute").Cells(1, attributerowcounter)), True).Value
With Sheets("08-Attribute")
If "9,AttributeRowCounter" = "CFM" Then
.Range("11,AttributeRowCounter").Value = Sheets("JCX").Range("14,TagNumberRow").Value
ElseIf "9" = "SP" Then
.Range("11,AttributeRowCounter").Value = Sheets("JCX").Range("15,TagNumberRow").Value
ElseIf "9" = "RPM" Then
.Range("11,AttributeRowCounter").Value = Sheets("JCX").Range("16,TagNumberRow").Value
ElseIf "9" = "Motor_HP" Then
.Range("11,AttributeRowCounter").Value = Sheets("JCX").Range("17,TagNumberRow").Value
Else
.Range("9,AttributeRowCounter").Value = Sheets("JCX").Range("20,TagNumberRow").Value
TagValueNameColumn = TagValueNameColumn + 2
.Range("11,AttributeRowCounter").Value = Sheets("JCX").Range("21,TagNumberRow").Value
TagValueNameColumn = TagValueNameColumn + 2
End If 'new
End With 'new
End With 'new
Loop Until Cells(1, attributerowcounter) = False
靠近底部和'new
末尾的三行是关闭If
块和两个With
块所必需的。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句