[英]Transferring data with in workbooks
伙計們和加爾斯,我一直堅持在我一直在努力的這段代碼上,不斷出錯,說我有一個下一個,但是沒有一個,因為我只有兩個fors和兩個下一個。 任何幫助,將不勝感激。
子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
始終縮進您的代碼。 這樣,您可以看到缺少的內容。 看到這個
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
您不見了, End If
在'~~~> SOMETHING IS MISSING HERE????
缺少某項,則End If
'~~~> SOMETHING IS MISSING HERE????
If inmatch = "" Then
這是在進入之前。 如果wsCopy2.Range(“ c2”)> 0然后,如果您評論缺少某些內容,我嘗試嘗試另一端。 但它並不喜歡– Rubberduckiegod 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.