Please see if either of following two set of codes is useful to you.
- Mention your Source File Path & File name directly as string
Sub GetData()
Dim customerFilename As String
Dim customerWorkbook As Workbook
Dim targetSheet As Worksheet, sourceSheet As Worksheet
'targetSheet is Activeworkbook wherein you would want to fetch the data
Set targetSheet = ActiveWorkbook.Worksheets("Sheet1")
'Mention Source-file path & file name between double quotes below
customerFilename = "C:\Users\YIT\Documents\test\April57\Your_File_Name_Here.xls"
Set customerWorkbook = Application.Workbooks.Open(customerFilename)
Set sourceSheet = customerWorkbook.Worksheets("daily shift report")
sourceSheet.Range("B71:G77").Copy
'select in which cell you want to paste data
targetSheet.Range("A1").PasteSpecial Transpose:=True
customerWorkbook.Close
End Sub
- In this code you will be prompted to select Source File (.xls or .xlsx or .csv), no need to manually write Source Filepath & Filename.
Sub GetData2()
Dim filter As String, caption As String
Dim customerFilename As String
Dim customerWorkbook As Workbook
Dim targetSheet As Worksheet, sourceSheet As Worksheet
'targetSheet is Activeworkbook wherein you would want to fetch the data
Set targetSheet = ActiveWorkbook.Worksheets("Sheet1")
'Prompt to get the customerWorkbook i.e. Source Workbook
filter = "Excel and CSV Files (*.xls;*.xlsx;*.csv),*.xls;*.xlsx;*.csv"
caption = "Please Select an input file "
customerFilename = Application.GetOpenFilename(filter, , caption)
Set customerWorkbook = Application.Workbooks.Open(customerFilename)
Set sourceSheet = customerWorkbook.Worksheets("daily shift report")
sourceSheet.Range("B71:G77").Copy
'select in which cell you want to paste data
targetSheet.Range("A1").PasteSpecial Transpose:=True
customerWorkbook.Close
End Sub
Hope these codes are useful to you. Regards.
Everytime in Range("A1")
overwriting the existing contents? Is really that you want? Would you like to copy at the last empty row? Or on the next column? – FaneDuru