我想從一個工作簿中提取一列並嘗試將其粘貼到另一個工作簿中。錯誤:對象不支持此屬性或方法
的代碼工作正常,我完全失去了,爲什麼我在該行收到此錯誤
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