0

我遇到了一个简单的代码错误 1004,或者根据我使用的代码未定义 Sub。我需要帮助比较两个不同工作表中的数字,然后替换其中一个 rowa 中的值。 (例如 sheet1 "A1" = 809565 匹配 Sheet2 "A28" = 809565,然后我必须将当前字符串更改为 "Above Ground(I)"。)

Set dbsheet = ThisWorkbook.Sheets("Sheet1")
Set dbsheet_1 = ThisWorkbook.Sheets("Export_For_WMIS_Recon")

Col_Len = dbsheet.Cells(Rows.Count, 1).End(x1UP).Row
Col_Len_1 = dbsheet_1.Cells(Rows.Count, 1).End(x1UP).Row

For x = 1 To Col_Len

     For i = 1 To Col_Len_1
        Search_num = dbsheet.Cells(x, 1)
        Comp_num = dbsheet_1.Cells(i, 1)
        Comp_word = dbsheet_1.Cells(i, 3)
        If Search_# = Comp_# And Comp_word = "Aboveground" Then
            Comp_word = "ABOVE GROUND(I)"
        End If
     Next i
Next x
End Sub

代码 2:

row_number = 0
r_number_2 = 0

Do
DoEvent
r_number_2 = r_number_2 + 1
Search_# = ThisWorkbook.Sheets("Sheet1").Range("A" & row_number)
Comp_# = ThisWorkbook.Sheets("Export_For_WMIS_Recon").Range("A" & row_number)
    If Search_# = Comp_# And ThisWorkbook.Sheets("Export_For_WMIS_Recon").Range("C" & row_number) = "Aboveground" Then
        ThisWorkbook.Sheets("Export_For_WMIS_Recon").Range("C" & row_number) = "ABOVE GROUND(I)"
    End If
Loop Until Comp_# = ""

循环直到 Search_# = ""

4

1 回答 1

0

我想这就是你要找的:

Sub tgr()

    Dim ws1 As Worksheet
    Dim ws2 As Worksheet
    Dim rngFound As Range
    Dim varFind As Variant
    Dim strFirst As String

    Set ws1 = ThisWorkbook.Sheets("Sheet1")
    Set ws2 = ThisWorkbook.Sheets("Export_For_WMIS_Recon")

    For Each varFind In ws1.Range("A1", ws1.Cells(Rows.Count, "A").End(xlUp)).Value
        Set rngFound = ws2.Columns("A").Find(varFind, ws2.Cells(Rows.Count, "A"), xlValues, xlWhole)
        If Not rngFound Is Nothing Then
            strFirst = rngFound.Address
            Do
                If LCase(ws2.Cells(rngFound.Row, "C").Value) = "aboveground" Then
                    ws2.Cells(rngFound.Row, "C").Value = "ABOVE GROUND(I)"
                End If
                Set rngFound = ws2.Columns("A").Find(varFind, rngFound, xlValues, xlWhole)
            Loop While rngFound.Address <> strFirst
        End If
    Next varFind

    Set ws1 = Nothing
    Set ws2 = Nothing
    Set rngFound = Nothing

End Sub
于 2013-08-19T20:59:59.503 回答