Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Sub ImportData()
- Dim HistoryTool As Workbook
- Dim CWB As Workbook
- Dim TargetSummSheet As Range
- Dim cls, LR As Long, i As Long
- Set HistoryTool = ActiveWorkbook
- cls = Array("C3", "C4", "C5", "C6", "C10")
- With Application.FileDialog(msoFileDialogOpen)
- .Filters.Clear
- .Filters.Add "Excel Files", "*.xlsx*;*.xlsm*;*.xlsa*;*.xm*"
- .AllowMultiSelect = False
- .Show
- If .SelectedItems.Count > 0 Then
- Workbooks.Open .SelectedItems(1)
- Set CWB = ActiveWorkbook
- Set TargetSummSheet = Application.InputBox(prompt:="Select source sheet (select any cell)", Title:="Source sheet", Default:="A1", Type:=8)
- With HistoryTool.Sheets("Import Cost Helper")
- For i = LBound(cls) To UBound(cls)
- .Range("B7").Offset(, i).Value = TargetSummSheet.Parent.Range(cls(i)).Value 'may have to adjust CWB sheet ref
- Next i
- .Range("B7:AD7").EntireColumn.AutoFit
- End With
- CWB.Close False
- End If
- End With
- End Sub
Add Comment
Please, Sign In to add comment