我和加尔斯一直坚持在我一直在努力的这段代码上,不断出错,说我有一个下一个,但没有一个,因为我只有两个fors和两个下一个。任何帮助,将不胜感激。
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
Next
End If
End Sub
答案 0 :(得分:2)
始终缩进代码。这样,您可以看到缺少的内容。看到这个
Arial
https://www.com/test1.woff
Arial Italic
https://www.com/test2.woff
您丢失了,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
的{{1}}的{{1}}
这是在进入之前。如果wsCopy2.Range(“ c2”)> 0然后,如果您评论缺少某些内容,我尝试尝试另一端。但它不喜欢– 5分钟前rubberduckiegod
我认为您将其插入错误的位置。这是您的完整代码
End If
答案 1 :(得分:0)
这可能会有所帮助:
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