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

时间:2019-02-01 19:57:02

标签: excel vba

因此,我尝试将一个工作表上的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

1 个答案:

答案 0 :(得分:0)

Sub ADDING()     昏暗的wsCopy作为工作表       昏暗的wsCopy3作为工作表     Dim i2作为整数     Dim inrow2作为整数     Dim inmatch2作为字符串     昏暗k2作为整数     Dim 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

结束子