我正在遍历列(B 到 E)并尝试从每列获取唯一值到不同工作簿中的单元格。迭代只发生一次,不会重复(当 x=3 时),并且出现运行时错误 1004:应用程序定义或对象定义错误
Dim LastCellRow As Integer
Dim inputRng As Range
Dim rng As Range
LastCellRow = Workbooks(MainFile).Sheets(1).Range("N3").End(xlDown).Row
For x=2 To 5
wkbTemp.Worksheets("Specific").Range(Cells(2, x), Cells(2, x).End(xlDown)).AdvancedFilter Action:=xlFilterCopy, CriteriaRange:="", CopyToRange:=Workbooks(MainFile).Worksheets(1).Range("I4"), Unique:=True
Workbooks(MainFile).Sheets(1).Activate
LastCell = Range("I5").End(xlDown).Address
For Each rng In Range(Cells(5, 9), LastCell)
If Cells(LastCellRow + 1, x + 12) = "" Then
Cells(LastCellRow + 1, x + 12) = rng.Value
Else
Cells(LastCellRow + 1, x + 12) = Cells(LastCellRow + 1, x + 12) & "," & rng.Value
End If
Next
Next
在网上研究之后,我尝试了这个选项以及它们的组合。我还尝试在迭代之前激活wkbTemp或MainFile,但没有运气。
With wkbTemp.Sheets("Specific")
wkbTemp.Worksheets("Specific").Range(.Cells(2, x), .Cells(2, x).End(xlDown)).AdvancedFilter Action:=xlFilterCopy, CriteriaRange:="", CopyToRange:=Workbooks(MainFile).Worksheets(1).Range("I4"), Unique:=True
End With
谢谢!