比较列然后最后一行之后添加文本

问题描述 投票:0回答:1

所以我试图比较G1:在一个工作表G51到M11:M15如果发现匹配,然后去旁边空白的“M”来跳过,并插入一个文本是在“G”,保存着wsDest.Range(“M”示数)= inmatch2。我究竟做错了什么?

    Dim wsCopy As Worksheet
    Dim wsCopy3 As Worksheet
    Dim i2 As Integer
    Dim inrow2 As Integer
    Dim inmatch2 As String
    Dim k2 As Integer
    Dim outrow2 As Integer
    Dim outmatch2 As String


'Set variables for copy and destination sheets
    Set wsCopy = Worksheets("Sheet1")   
    Set wsCopy3 = Worksheets("Sheet3")

    If wsCopy3.Range("b1") > 0 Then     

    inrow2 = 10     
        For i2 = 1 To inrow2
            inmatch2 = wsCopy.Range("a" & i2)

        If inmatch2 = "" Then Exit For

    outrow2 = 25
        For k2 = 1 To outrow2
            outmatch2 = wsCopy3.Range("b" & k2)

            If outmatch2 = inmatch2 Then
                Exit For
            End If

           If outmatch2 = "" Then
                wsCopy3.Range("b" & k2) = inmatch2
                Exit For
            End If
        Next

            If outmatch2 = "" Then
                Exit For
            End If
        Next
    End If
End Sub

excel vba
1个回答
0
投票

子ADDING()昏暗wsCopy作为工作表昏暗wsCopy3作为工作表昏暗I2作为整数昏暗inrow2作为整数昏暗inmatch2作为字符串昏暗K2作为整数昏暗outrow2作为整数昏暗outmatch2作为字符串

'Set variables for copy and destination sheets
Set wsCopy = Worksheets("Sheet1")

Set wsCopy3 = Worksheets("Sheet3")


If wsCopy3.Range("b1") > 0 Then


    inrow2 = 10


    For i2 = 1 To inrow2
        inmatch2 = wsCopy.Range("a" & i2)
        If inmatch2 = "" Then Exit For

        outrow2 = 25
        For k2 = 1 To outrow2
            outmatch2 = wsCopy3.Range("b" & k2)
            If outmatch2 = inmatch2 Then
            Exit For
            End If

            If outmatch2 = "" Then
            wsCopy3.Range("b" & k2) = inmatch2
                Exit For
            End If
        Next

        If outmatch2 = "" Then
                Exit For
        End If
    Next

End If

结束小组

© www.soinside.com 2019 - 2024. All rights reserved.