How can a range of cells be copied from one workbook to another? The code below does not work. I believe there is something wrong with how the range of cells are selected: sht1.Range("A1:D1").Select
Sub ImportData() Dim wkb1 As Workbook Dim sht1 As Worksheet Dim wkb2 As Workbook Dim sht2 As Worksheet Application.ScreenUpdating = False Set wkb1 = ThisWorkbook Set wkb2 = Workbooks.Open("C:\Users\Temp\Desktop\MyExcelSheet.xlsm") Set sht1 = wkb1.Sheets("Data") Set sht2 = wkb2.Sheets("Summary") 'Function to clear the existing data. Doesn't work. sht1.Range("A1:D1").Select sht1.Range(Selection, Selection.End(xlDown)).Select Selection.ClearContents ' Copies data from the "Summary" sheet. sht2.Range("O6:P102").Copy sht2.Range("O6").Select sht2.Range(Selection, Selection.End(xlToRight)).Select sht2.Range(Selection, Selection.End(xlDown)).Select Selection.Copy ' Copies all of the highlighted cells. sht1.Range("A1").PasteSpecial xlPasteValues Application.CutCopyMode = False wkb2.Close True Application.ScreenUpdating = True MsgBox "Complete" End Sub
select. Find last row and last column. Also, if pasting values, just set ranges to each other.