Ok, so this is my dilema, I am trying to set up a template that can copy data from a sheet in one workbook and paste it in to another. So why am I failing.
The code is below. The first part opens the workbook that is designated in cell B3. Next I need to copy the data from that workbook on the database worksheet that starts at A10, the range varies so I have used currentRegion.copy. And finally it needs to paste it on the worksheet named project 1 in Portfolio Rollup Sample.xlsm file. I have tried to use paste special so that the numbers remain the correct format and no links to the original spreadsheet are retained.
Ultimately I am going to have to get this to loop through to repeat with different source files, all set up the same as the first, on to sheets project 2, 3 etc.
Sub ImportDatabases()
Dim ExtFile As String
Dim ExtBk As Workbook
ExtFile = Range("B3").Value
If Not ExtFile = "" And Dir(ExtFile) <> "" Then
Else
ExtFile = Application.GetOpenFilename(FileFilter:="microsoft excel files (*.xls), *.xls", Title:="Please Select A File")
End If
On Error Resume Next
Set ExtBk = Workbooks(Dir(ExtFile))
On Error GoTo 0
If ExtBk Is Nothing Then
Application.Workbooks.Open ExtFile
Set ExtBk = Workbooks(Dir(ExtFile))
End If
'TO HERE OPENS THE FIRST FILE
'THIS NEXT BIT IS TO COPY AND PASTE THE DATABASE
Worksheets("Database").Activate
Range("A10").CurrentRegion.Copy
Workbooks("Portfolio Rollup Sample.xlsm").Worksheets("Project 1").Range("A1").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
End Sub
All help to resolve what I am sure is a simple problem much appreciated.
The code is below. The first part opens the workbook that is designated in cell B3. Next I need to copy the data from that workbook on the database worksheet that starts at A10, the range varies so I have used currentRegion.copy. And finally it needs to paste it on the worksheet named project 1 in Portfolio Rollup Sample.xlsm file. I have tried to use paste special so that the numbers remain the correct format and no links to the original spreadsheet are retained.
Ultimately I am going to have to get this to loop through to repeat with different source files, all set up the same as the first, on to sheets project 2, 3 etc.
Sub ImportDatabases()
Dim ExtFile As String
Dim ExtBk As Workbook
ExtFile = Range("B3").Value
If Not ExtFile = "" And Dir(ExtFile) <> "" Then
Else
ExtFile = Application.GetOpenFilename(FileFilter:="microsoft excel files (*.xls), *.xls", Title:="Please Select A File")
End If
On Error Resume Next
Set ExtBk = Workbooks(Dir(ExtFile))
On Error GoTo 0
If ExtBk Is Nothing Then
Application.Workbooks.Open ExtFile
Set ExtBk = Workbooks(Dir(ExtFile))
End If
'TO HERE OPENS THE FIRST FILE
'THIS NEXT BIT IS TO COPY AND PASTE THE DATABASE
Worksheets("Database").Activate
Range("A10").CurrentRegion.Copy
Workbooks("Portfolio Rollup Sample.xlsm").Worksheets("Project 1").Range("A1").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
End Sub
All help to resolve what I am sure is a simple problem much appreciated.