Excel 使用工作簿中的

Excel 使用工作簿中的,excel,vba,Excel,Vba,小伙子们,姑娘们,我一直在写这段代码,不断出错,说我有下一个,但没有,因为我只有两个for和两个next。任何帮助都将不胜感激 副秘书长2() 始终缩进代码。这样你就可以看到遗漏了什么。看到这个了吗 For i = 2 To inrow inmatch = wsCopy2.Range("d" & i) If inmatch = "" Then Exit For outrow = 1000 For k = 2 To outr

小伙子们,姑娘们,我一直在写这段代码,不断出错,说我有下一个,但没有,因为我只有两个for和两个next。任何帮助都将不胜感激

副秘书长2()


始终缩进代码。这样你就可以看到遗漏了什么。看到这个了吗

For i = 2 To inrow
    inmatch = wsCopy2.Range("d" & i)
    If inmatch = "" Then
        Exit For
        outrow = 1000

        For k = 2 To outrow
            outmatch = wsDest2.Range("A" & k)
            If outmatch = inmatch Then
                Exit For
            End If

            If outmatch = "" Then
                wsDest2.Range("A" & k) = inmatch
                Exit For
            End If
        Next

        If outmatch = inmatch Then
            Exit For
        End If
    '~~~> SOMETHING IS MISSING HERE????
Next
如果在处~~~>有东西丢失了,您就丢失了,
结束了???
对于
如果inmatch=“”,那么

这是在涌进之前。如果wsCopy2.Range(“c2”)>0,那么如果您评论缺少某些内容,我会尝试将另一端放在另一端。但它不喜欢这样——5分钟前的橡皮泥上帝

我想你插错地方了。这是您的完整代码

Sub TRANS2()
    Dim wsCopy2 As Worksheet
    Dim wsDest2 As Worksheet
    Dim i As Integer
    Dim inrow As Integer
    Dim inmatch As String
    Dim inpax As Integer
    Dim k As Integer
    Dim outrow As Integer
    Dim outmatch As String
    Set wsCopy2 = Workbooks("CargoReport1.xlsx").Worksheets("CargoReport")
    Set wsDest2 = Workbooks("w1.xlsm").Worksheets("Sheet1")

    If wsCopy2.Range("c2") > 0 Then
        inrow = 1000

        For i = 2 To inrow
            inmatch = wsCopy2.Range("d" & i)
            If inmatch = "" Then
                Exit For
                outrow = 1000
                For k = 2 To outrow
                    outmatch = wsDest2.Range("A" & k)
                    If outmatch = inmatch Then
                        Exit For
                    End If

                    If outmatch = "" Then
                        wsDest2.Range("A" & k) = inmatch
                        Exit For
                    End If
                Next

                If outmatch = inmatch Then
                     Exit For
                End If
            End If
        Next
    End If
End Sub

始终缩进代码。这样你就可以看到遗漏了什么。看到这个了吗

For i = 2 To inrow
    inmatch = wsCopy2.Range("d" & i)
    If inmatch = "" Then
        Exit For
        outrow = 1000

        For k = 2 To outrow
            outmatch = wsDest2.Range("A" & k)
            If outmatch = inmatch Then
                Exit For
            End If

            If outmatch = "" Then
                wsDest2.Range("A" & k) = inmatch
                Exit For
            End If
        Next

        If outmatch = inmatch Then
            Exit For
        End If
    '~~~> SOMETHING IS MISSING HERE????
Next
如果在处~~~>有东西丢失了,您就丢失了,
结束了???
对于
如果inmatch=“”,那么

这是在涌进之前。如果wsCopy2.Range(“c2”)>0,那么如果您评论缺少某些内容,我会尝试将另一端放在另一端。但它不喜欢这样——5分钟前的橡皮泥上帝

我想你插错地方了。这是您的完整代码

Sub TRANS2()
    Dim wsCopy2 As Worksheet
    Dim wsDest2 As Worksheet
    Dim i As Integer
    Dim inrow As Integer
    Dim inmatch As String
    Dim inpax As Integer
    Dim k As Integer
    Dim outrow As Integer
    Dim outmatch As String
    Set wsCopy2 = Workbooks("CargoReport1.xlsx").Worksheets("CargoReport")
    Set wsDest2 = Workbooks("w1.xlsm").Worksheets("Sheet1")

    If wsCopy2.Range("c2") > 0 Then
        inrow = 1000

        For i = 2 To inrow
            inmatch = wsCopy2.Range("d" & i)
            If inmatch = "" Then
                Exit For
                outrow = 1000
                For k = 2 To outrow
                    outmatch = wsDest2.Range("A" & k)
                    If outmatch = inmatch Then
                        Exit For
                    End If

                    If outmatch = "" Then
                        wsDest2.Range("A" & k) = inmatch
                        Exit For
                    End If
                Next

                If outmatch = inmatch Then
                     Exit For
                End If
            End If
        Next
    End If
End Sub
这可能有助于:

Option Explicit

Sub TRANS2()

    Dim wsCopy2 As Worksheet, wsDest2 As Worksheet
    Dim i As Long, inrow As Long, inpax As Long, outrow As Long, k As Long
    Dim inmatch As String, outmatch As String

    Set wsCopy2 = Workbooks("CargoReport1.xlsx").Worksheets("CargoReport")
    Set wsDest2 = Workbooks("w1.xlsm").Worksheets("Sheet1")

    If wsCopy2.Range("c2") > 0 Then

        inrow = 1000

        For i = 2 To inrow
            inmatch = wsCopy2.Range("d" & i).Value
            If inmatch = "" Then
                Exit For
            End If

            outrow = 1000

            For k = 2 To outrow
                outmatch = wsDest2.Range("A" & k).Value
                If outmatch = inmatch Then
                    Exit For
                End If

                If outmatch = "" Then
                    wsDest2.Range("A" & k).Value = inmatch
                    Exit For
                End If
            Next k

                If outmatch = inmatch Then
                    Exit For
                End If
        Next i

    End If

End Sub
这可能有助于:

Option Explicit

Sub TRANS2()

    Dim wsCopy2 As Worksheet, wsDest2 As Worksheet
    Dim i As Long, inrow As Long, inpax As Long, outrow As Long, k As Long
    Dim inmatch As String, outmatch As String

    Set wsCopy2 = Workbooks("CargoReport1.xlsx").Worksheets("CargoReport")
    Set wsDest2 = Workbooks("w1.xlsm").Worksheets("Sheet1")

    If wsCopy2.Range("c2") > 0 Then

        inrow = 1000

        For i = 2 To inrow
            inmatch = wsCopy2.Range("d" & i).Value
            If inmatch = "" Then
                Exit For
            End If

            outrow = 1000

            For k = 2 To outrow
                outmatch = wsDest2.Range("A" & k).Value
                If outmatch = inmatch Then
                    Exit For
                End If

                If outmatch = "" Then
                    wsDest2.Range("A" & k).Value = inmatch
                    Exit For
                End If
            Next k

                If outmatch = inmatch Then
                    Exit For
                End If
        Next i

    End If

End Sub

这是在涌进之前。如果wsCopy2.Range(“c2”)>0,那么如果您评论缺少某些内容,我会尝试将另一端放在另一端。但我不喜欢这样:)你确定你完全按照我的要求做了吗?看更新的帖子,我已经粘贴了你的完整代码。。。您可能需要刷新页面才能看到它。这是在inrow之前。如果wsCopy2.Range(“c2”)>0,那么如果您评论缺少某些内容,我会尝试将另一端放在另一端。但我不喜欢这样:)你确定你完全按照我的要求做了吗?看更新的帖子,我已经粘贴了你的完整代码。。。您可能需要刷新页面才能看到它。