Hi everyone
Please could someone try and help me?
I am using the below code which works, it essentially is importing a set range of data from one worksheet into my main worksheet.
What I need to do is set the worksheet name as currently it just imports the data into the activework sheet.
Can anyone help me please? Say using the worksheet name as 'WorksheetName'.
Please could someone try and help me?
I am using the below code which works, it essentially is importing a set range of data from one worksheet into my main worksheet.
What I need to do is set the worksheet name as currently it just imports the data into the activework sheet.
Can anyone help me please? Say using the worksheet name as 'WorksheetName'.
Code:
Sub Import1()
' Get customer workbook...
Dim customerBook As Workbook
Dim filter As String
Dim caption As String
Dim customerFilename As String
Dim customerWorkbook As Workbook
Dim targetWorkbook As Workbook
' make weak assumption that active workbook is the target
Set targetWorkbook = Application.ActiveWorkbook
' get the customer workbook
filter = "Text files (*.xls),*.xls"
caption = "Please select the Timesheets "
customerFilename = Application.GetOpenFilename(filter, , caption)
Set customerWorkbook = Application.Workbooks.Open(customerFilename)
' assume range is A2 - K200 in sheet1
' copy data from customer to target workbook
Dim targetSheet As Worksheet
Set targetSheet = targetWorkbook.Worksheets(1)
Dim sourceSheet As Worksheet
Set sourceSheet = customerWorkbook.Worksheets(1)
targetSheet.Range("A2", "K500").Value = sourceSheet.Range("A2", "K500").Value
' Close customer workbook
customerWorkbook.Close
' targetSheet.Range("M3").Value = customerFilename
Range("N4").Select
ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
Range("A1").Select
End Sub