我真的需要一些帮助。
问题:我有一个包含2个工作表的工作簿。两张纸都有标题。 Sheet1是A列中的帐号列表,而对于表2列A则相同。现在,我需要做的是:
我希望我解释得这么多。以下是我到目前为止所提出的问题,但却被卡住了:
Sub UpdateTBP()
Dim i
Dim j
Dim k
Dim LastRow
Dim LastRow2
LastRow = Sheets("Portfolio").Cells(Rows.Count, 1).End(xlUp).Row
LastRow2 = Sheets("TBP").Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To (LastRow - 1)
For j = 2 To (LastRow2 - 1)
If Sheets("Portfolio").Cells(i, 1) = Sheets("TBP").Cells(j, 1).value Then
For k = 35 To 35
If Sheets("TBP").Cells(j, 35) <> "" Then
Sheets("Portfolio").Cells(i, Y).value = "Complete"
End If
Next
End If
Next
Next
ThisWorkbook.Save
End Sub
答案 0 :(得分:0)
我能够通过使用以下修改后的代码使其工作:
Sub UpdateTBP()
Dim i
Dim j
Dim k
Dim LastRow
Dim LastRow2
LastRow = Sheets("Portfolio").Cells(Rows.Count, 1).End(xlUp).Row
LastRow2 = Sheets("TBP").Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To (LastRow - 1)
For j = 2 To (LastRow2 - 1)
If Sheets("Portfolio").Cells(i, 1).Value = Sheets("TBP").Cells(j, 1).Value Then
If Sheets("TBP").Cells(j, 35) <> "" Then
Sheets("Portfolio").Cells(i, 25).Value = "Complete"
End If
End If
Next
Next
ThisWorkbook.Save
End Sub
请注意,这不包括您的最后一行数据,因为您已将其减去:
For i = 2 To (LastRow - 1)
For j = 2 To (LastRow2 - 1)
如果您希望包含最后一行,请使用以下内容:
For i = 2 to LastRow
For j = 2 to LastRow2
这包括我之前的评论。我刚给它一个快速测试,它正在工作。