0

我有以下代码从列中提取数据,如果它首先在原始数据集中输入 - 这在 atm 中完美工作,但我试图让它输入原始数据中找不到的任何内容。

到目前为止我有这个 -
Sub FactoryForum()

Dim Main_Sheet: Set Main_Sheet = Worksheets("Main_Sheet")
Dim Factory_Forum: Set Factory_Forum = Worksheets("Factory_Forum")
Dim x As Integer
Dim y As Integer
Dim lastRow As Integer
Dim a As String
Dim RowCounter As Integer


RowCounter = Worksheets("Main_Sheet").Range("A1").CurrentRegion.Rows.Count
'lastrow = ("A1" + RowCounter)

Main_Sheet.Range("V2:V800").ClearContents

For x = 2 To RowCounter
a = Right(Main_Sheet.Cells(x, 3), 6)
For y = 2 To RowCounter

If InStr(Factory_Forum.Cells(y, 11), a) > 0 Then
    Main_Sheet.Cells(x, 22).Value = "YES"
End If

Next
Next

MsgBox ("DONE :)")
End Sub

那行得通-

我试过这个 - 但它只是删除了所有原始数据。子 Add_Parts_To_WR()

Dim Main_Sheet: Set Main_Sheet = Worksheets("Main_Sheet")
Dim Factory_Forum: Set Factory_Forum = Worksheets("Factory_Forum")
Dim xx As Integer
Dim yy As Integer
Dim lastrow As Integer
Dim aa As String
Dim RowCounterFF As Integer

RowCounterFF = Worksheets("Main_Sheet").Range("A1").CurrentRegion.Rows.Count

For xx = 2 To RowCounterFF
aa = Right(Main_Sheet.Cells(xx, 3), 6)
For yy = 2 To RowCounterFF

 If InStr(Factory_Forum.Cells(yy, 11), aa) <> Main_Sheet.Cells(xx, 3).Value Then
     Main_Sheet.Cells(xx, 3).Value = Factory_Forum.Cells(yy, 11)
 End If

Next
Next


End Sub

请帮忙

4

0 回答 0