0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

vba sheetデータ纏める

Last updated at Posted at 2022-07-08

自分の覚書

Sub TEST4()
  
  Dim row, ws, wb
  Set ws = ThisWorkbook.Worksheets("Sheet1")
  'フォルダ内のブック名を取得
  wb = Dir("C:\Users\Wataru.VAIO\Desktop\プログラミング" & "\*.xlsx")
  Debug.Print wb
  '"C:\Users\Wataru.VAIO\Desktop\プログラミング"
  
  
  
  Do While wb <> ""
    'ブックを開く
    Workbooks.Open "C:\Users\Wataru.VAIO\Desktop\プログラミング\" & wb
    'データ部分を取得
    With ActiveWorkbook.Worksheets("Sheet1").Range("A1").CurrentRegion
      row = .Rows("2:" & .Rows.Count)
    End With
    'データを入力
    ws.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).Resize(UBound(row, 1), 10) = row
    ActiveWorkbook.Close False 'ブックを閉じる
    wb = Dir() '次のブック名を取得
  Loop
  
End Sub

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?