2016-07-11 10 views
2

範囲内で「開く」ブックのすべてのデータエントリを選択するコードを作成していましたが、最後の行にエラーが表示されます(Range rngを設定します)VBA:範囲メソッドのエラー

Dim wb As Workbook 
Set wb = Workbooks.Open(Range("C2") & Range("C3")) 
'here Range("C2") & Range("C3") contains the location of the file's path 
Dim ws As Worksheet 
Set ws = wb.ActiveSheet 
Dim frow As Long 
frow = ws.Range("A" & Rows.count).End(xlUp).Row 
Dim rng As Range 
Dim frow1 As Long 
frow1 = ws.Cells(1, Columns.count).End(xlToLeft).Column 
Set rng = wb.ActiveSheet.Range(Cells(1, 1), Cells(frow, frow1)) 
+0

'設定し、WB = Workbooks.Open(レンジ( "C2")&オブジェクトuは、すべての範囲でそれを参照する必要があることを忘れないでください範囲( "C3"))それは間違っています。範囲の代わりに開くブックのパスを指定します。 – skkakkar

+0

範囲C2とC3の値を掲示してください。 –

+0

ファイルパスが含まれています。質問を編集しました。 –

答えて

2

試してみてください。

Dim frow As Long 
frow = ws.Range("A" & ws.Rows.count).End(xlUp).Row 
Dim rng As Range 
Dim fcol As Long 
fcol = ws.Cells(1, ws.Columns.count).End(xlToLeft).Column 
Set rng = ws.Range(ws.Cells(1, 1), ws.Cells(frow, fcol)) 

あなたが設定したワークシートを使用している場合

+1

' Cells(frow、frow1) 'の前に' ws.'が必要だと思います。 – Fadi

+0

右...申し訳ありませんheheは1つを逃しました... –