Guest User

Untitled

a guest
Apr 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. Option Explicit
  2.  
  3. Sub ImportData()
  4.  
  5. Dim HistoryTool As Workbook
  6. Dim CWB As Workbook
  7. Dim TargetSummSheet As Range
  8. Dim cls, LR As Long, i As Long
  9.  
  10. Set HistoryTool = ActiveWorkbook
  11.  
  12. cls = Array("C3", "C4", "C5", "C6", "C10")
  13.  
  14. With Application.FileDialog(msoFileDialogOpen)
  15. .Filters.Clear
  16. .Filters.Add "Excel Files", "*.xlsx*;*.xlsm*;*.xlsa*;*.xm*"
  17. .AllowMultiSelect = False
  18. .Show
  19. If .SelectedItems.Count > 0 Then
  20. Workbooks.Open .SelectedItems(1)
  21. Set CWB = ActiveWorkbook
  22. Set TargetSummSheet = Application.InputBox(prompt:="Select source sheet (select any cell)", Title:="Source sheet", Default:="A1", Type:=8)
  23. With HistoryTool.Sheets("Import Cost Helper")
  24. For i = LBound(cls) To UBound(cls)
  25. .Range("B7").Offset(, i).Value = TargetSummSheet.Parent.Range(cls(i)).Value 'may have to adjust CWB sheet ref
  26. Next i
  27. .Range("B7:AD7").EntireColumn.AutoFit
  28. End With
  29. CWB.Close False
  30. End If
  31. End With
  32.  
  33. End Sub
Add Comment
Please, Sign In to add comment