|
なつみ さん
こんばんは。
こんな感じのことがしたいのかな・・・。と私なりの理解でつくってみました。
以下を試してみて下さい。
Sub 統合()
Const Fldpth As String = "C:\"
Const TmpFnm As String = "売上"
Const ShtNm As String = "SHEET1"
Dim i As Long, TmpCnt As Long, R_Cnt As Long
Dim F_Nm As String
R_Cnt = 1
For i = 1 To 10 Step 1
F_Nm = Fldpth & TmpFnm & IIf(i < 10, "0" & CStr(i), CStr(i)) & ".SLK"
If Dir(F_Nm) = "" Then
MsgBox "ファイルが存在しません" & vbCrLf & F_Nm
ThisWorkbook.Sheets(ShtNm).Cells.ClearContents
Exit Sub
End If
Workbooks.Open F_Nm
With ActiveSheet
TmpCnt = .Range("A65536").End(xlUp).Row
.Range("A1:M" & CStr(TmpCnt)).Copy ThisWorkbook.Sheets("sheet1").Range("A" & R_Cnt)
End With
ActiveWorkbook.Close False
ThisWorkbook.Sheets(ShtNm).Range("N" & CStr(R_Cnt) & ":N" & CStr(R_Cnt + TmpCnt)) = i
R_Cnt = R_Cnt + TmpCnt
Next
ThisWorkbook.Sheets(ShtNm).Range("A1:M" & CStr(R_Cnt)).NumberFormatLocal = "G/標準"
End Sub
|
|