[ 初めての方へ | 一覧(最新更新順) | 全文検索 | 過去ログ ]
『質問をさせてください』(sk)
'1枚のシートに全csvファイルを取り込み Dim myPath As String Dim fName As String Dim csv As Workbook Dim sh As Worksheet Dim z As Long Dim lCell As Range
Application.ScreenUpdating = False Set sh = ThisWorkbook.Sheets("Sheet1") '取り込みシート名 実際のものに sh.Cells.ClearContents z = 1 '取り込み先の行番号 myPath = ThisWorkbook.Path & "\" fName = Dir(myPath & "*.csv")
Do While Len(fName) > 0 Set csv = Workbooks.Open(myPath & fName) With csv.Sheets(1) With .UsedRange Set lCell = .Cells(.Count) End With sh.Cells(z, "A").Resize(lCell.Row, lCell.Column).Value = .Range("A1", lCell).Value End With z = z + lCell.Row csv.Close False fName = Dir() Loop
Set sh = Nothing Set lCell = Nothing Set csv = Nothing Application.ScreenUpdating = True MsgBox "取り込み完了"
End Sub
まず、質問のタイトル、適切じゃないね。何に関する質問かを、見ただけでわかるものにしよう。
・取り込み先をA2からにする。 z = 1 '取り込み先の行番号 --> z = 2 '取り込み先の行番号
・csv側 A〜N
sh.Cells(Z, "A").Resize(lcell.Row, lcell.Column).Value = .Range("A1", lcell).Value
これを
sh.Range("A" & Z & ":N" & Z).Resize(lcell.Row).Value = .Range("A1:N" & lcell.Row).Value
それと、うえのほうにある sh.Cells.ClearContents --> sh.Columns("A:N").ClearContents
テストはしていないけど、まず、これぐらいで試してみて。
追記)O列にどんな数式が何行はいっているのかわからないけど、取り込むと同時に マクロで数式をセットすることもできるよ。むしろ、そうすべきじゃないかな?
(ぶらっと)
A2 からということは、取り込み先の1行目にはタイトル行があるのかな。 であれば、Dim Buff As Variant といったものを定義追加し Buff = Sh.Range("A1:N1").Value sh.Columns("A:N").ClearContents Sh.Range("A1:N1").Value = Buff
(ぶらっと)
[ 一覧(最新更新順) ]
YukiWiki 1.6.7 Copyright (C) 2000,2001 by Hiroshi Yuki.
Modified by kazu.