2017-08-06 19 views
1

あるブックから列を抽出し、別のブックに貼り付けようとしました。エラー:オブジェクトがこのプロパティまたはメソッドをサポートしていません

コードがうまく働いていた誰も私を助けてもらえ、私はラインで

Object does not support this property or method

LCELL = Selection.SpecialCells(xlCellTypeLastCell).Address

このエラーを取得していますなぜ、私は完全に失われていますその理由を理解する。以下は

非レンジは、マクロが実行された時点で編を選びある場合は、このタイプのエラーを取得することができ、完全なコード

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 

答えて

0

です。

など、チャート、いくつかの形状の範囲が選択されていることを確認し、ない

+0

私の問題を解決する方法はありますか? – Jenny

+1

@Jenny - [選択を使用しない](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba-macros) – Jeeped

+0

@ジープド私は疑いがある。私は問題を解決するためにドミニクのソリューションを使用しました。私は今、目的のシートにコピーされてわずか数行を取得します。私はデバッグしようとしましたが、その間に727行が選択されていました。あなたは何が問題になるかを提案できますか? – Jenny

1

また、あなたはしても、ワークシートの選択したセルを参照してくださいれる、WindowオブジェクトのRangeSelectionプロパティを使用することができますグラフィックオブジェクトが選択されています...

LCell = ActiveWindow.RangeSelection.SpecialCells(xlCellTypeLastCell).Address 
+0

この行を追加すると、 "Application defined error"という行が表示されます。Set temp = Range(CopyCol(Count)& "1: CopyCol(Count)&lcr) – Jenny

+0

私はこれをどのように取り除くことができますか? – Jenny

関連する問題