【发布时间】:2015-11-19 16:34:22
【问题描述】:
与 vba 脱节,所以我确信它在某个地方是一个愚蠢的错误。如果有人能指出这一点会非常有帮助
代码:
Private Function generate() As Integer
Dim source_size As Long
Dim target_size As Long
Dim i As Long
Dim j As Long
Dim count As Long
Dim source1 As Range
Dim target1 As Range
Set source1 = Worksheets("Filter").Range(C4, C6498)
Set target1 = Worksheets("30").Range(A2, AP95787)
source_size = source1.Height
target_size = target1.Height
For i = 1 To source_size Step 1
For j = 1 To target_size Step 1
If Application.source1.Cells(i, 1).Value = target1.Cells(j, 5).Value Then
target1.Row(j).Select
'Selection.Copy
Worksheet("result").Range("A1").Rows("1:1").Insert Shift:=xlDown
End If
Next j
Next i
generate = 0
End Function
【问题讨论】:
-
你从哪里得到错误?该代码的期望行为是什么?在编辑您的帖子以改进它之前,请花点时间阅读此链接:stackoverflow.com/help/how-to-ask
-
请参阅stackoverflow.com/questions/2237873/… 了解什么是 .Height 属性
-
可能
Range(d, C6498)以这种方式无效。你可以使用例如Range("A1:C3")或Range(Cells(...), Cells(...))。也许你想要Range("C4:C6498")?