|
ctrl + shift + * (CurrentRegion) で、最下行を判別してみました。
Sub Sample2()
Dim FileName As Variant
Dim wb As Workbook
Dim i As Long
Dim myRow As Long
FileName = Application.GetOpenFilename("Excelファイル (*.xls), *.xls")
If FileName = False Then
MsgBox "キャンセルされました"
Exit Sub
End If
Set wb = Workbooks.Open(FileName)
With ThisWorkbook.Worksheets("sheetDB")
myRow = .Range("B1").CurrentRegion.Row + 1
For i = 1 To wb.Worksheets.Count
Select Case Worksheets(i).Name
Case "Mois"
.Cells(2, myRow).Value = wb.Worksheets(i).Range("A1").Value
Case "NOS"
.Cells(3, myRow).Value = wb.Worksheets(i).Range("C2").Value
Case "SOL"
.Cells(4, myRow).Value = wb.Worksheets(i).Range("D4").Value
End Select
Next i
wb.Close False
End With
End Sub
|
|