我想从一个工作簿中提取一列并尝试将其粘贴到另一个工作簿中。错误:对象不支持此属性或方法
的代码工作正常,我完全失去了,为什么我在该行收到此错误
Object does not support this property or method
LCELL = Selection.SpecialCells(xlCellTypeLastCell)。地址
谁能帮我,找出原因。
下面是完整的代码
Sub Extractred()
Dim x As Workbook
Dim y As Workbook
Dim Val As Variant
Dim filename As String
Dim LastCell As Range
Dim LastRow As Long
CopyCol = Split("AK", ",")
LR = Cells(Rows.Count, 1).End(xlUp).Row
LC = Cells(1, Columns.Count).End(xlToLeft).Column
LCell = Selection.SpecialCells(xlCellTypeLastCell).Address
LCC = Selection.SpecialCells(xlCellTypeLastCell).Column
lcr = Selection.SpecialCells(xlCellTypeLastCell).Row
Set y = ThisWorkbook
'lcr = y.Cells(y.Rows.Count, "A").End(xlUp).Row
Dim path1, Path2
path1 = ThisWorkbook.Path
Path2 = path1 & "\Downloads"
Set x = Workbooks.Open(filename:=Path2 & "\Red.xlsx")
For Count = 0 To UBound(CopyCol)
Set temp = Range(CopyCol(Count) & "1:" & CopyCol(Count) & lcr)
If Count = 0 Then
Set CopyRange = temp
Else
Set CopyRange = Union(CopyRange, temp)
End If
Next
CopyRange.Copy
y.Sheets("All").Paste y.Sheets("All").Range("B4")
Application.CutCopyMode = False
x.Close
End Sub
有没有办法解决我的问题? – Jenny
@珍妮 - [不要使用选择](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba-macros)。 – Jeeped
@Jeeped我有疑问。我用domnik解决方案来解决问题。我现在只有几行被复制到目标工作表。我试图调试,在那段时间里,我可以看到727行被选中?你能提出什么问题 – Jenny