I am trying to create an Excel Macro that will do the following.
1. Prompt me to choose another excel sheet to to open and allow me to pick the file using MSO FILE DIALOG OPEN
2. CLear the contents of the one of the sheets on my workbook("Data")
3. Take the file that I Choose and copy range A1:1650 and then paste special with formating the cells into the current workbook to sheet("Data")
Right now I have a Macro that does this except that I have to choose the range with a Input box and I dont want to have to do that. Please see below.
Sub ImportData()
Dim wkbCrntWorkBook As Workbook
Dim wkbSourceBook As Workbook
Dim rngSourceRange As Range
Dim rngDestination As Range
Set wkbCrntWorkBook = ActiveWorkbook
With Application.FileDialog(msoFileDialogOpen)
.Filters.Clear
.Filters.Add "Excel 2002-03", "*.xls", 1
.Filters.Add "Excel 2007", "*.xlsx; *.xlsm; *.xlsa", 2
.AllowMultiSelect = False
.Show
Sheets("Data").Range("a1:l650").ClearContents
If .SelectedItems.Count > 0 Then
Workbooks.Open .SelectedItems(1)
Set wkbSourceBook = ActiveWorkbook
Set rngSourceRange = Application.InputBox(prompt:="Select source range", Title:="Source Range", Default:="A1:l650", Type:=8)
wkbCrntWorkBook.Activate
Set rngDestination = Application.InputBox(prompt:="Select destination cell", Title:="Select Destination", Default:="A1:l650", Type:=8)
rngSourceRange.Copy rngDestination
rngDestination.CurrentRegion.EntireColumn.AutoFit
wkbSourceBook.Close False
End If
End With
End Sub
Bookmarks