Advertisement
oshkoshbagoshh

enter data from another worksheet

Nov 28th, 2017
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub ImportDatafromotherworksheet()
  2.     Dim wkbCrntWorkBook As Workbook
  3.     Dim wkbSourceBook As Workbook
  4.     Dim rngSourceRange As Range
  5.     Dim rngDestination As Range
  6.     Set wkbCrntWorkBook = ActiveWorkbook
  7.     With Application.FileDialog(msoFileDialogOpen)
  8.         .Filters.Clear
  9.         .Filters.Add "Excel 2007-13", "*.xlsx; *.xlsm; *.xlsa"
  10.         .AllowMultiSelect = False
  11.         .Show
  12.         If .SelectedItems.Count > 0 Then
  13.             Workbooks.Open .SelectedItems(1)
  14.             Set wkbSourceBook = ActiveWorkbook
  15.             Set rngSourceRange = Application.InputBox(prompt:="Select source range", Title:="Source Range", Default:="A1", Type:=8)
  16.             wkbCrntWorkBook.Activate
  17.             Set rngDestination = Application.InputBox(prompt:="Select destination cell", Title:="Select Destination", Default:="A1", Type:=8)
  18.             rngSourceRange.Copy rngDestination
  19.             rngDestination.CurrentRegion.EntireColumn.AutoFit
  20.             wkbSourceBook.Close False
  21.         End If
  22.     End With
  23. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement