Code Problem - export to active workbook

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,340
Office Version
  1. 365
Platform
  1. Windows
This code is giving me problems at line: ActiveWorkbook.Sheets("PP Import").Range("A11").Select

Run-time error '1004':
Select method of Range class failed

Code:
Sub MoveReultsToTraker()


Dim sourceBook As Workbook
Dim targetBook As Variant
Dim sourceSheet As Worksheet
Dim targetSheet As Worksheet

Set sourceBook = ThisWorkbook
Set sourceSheet = sourceBook.Sheets("Results")

sourceSheet.Range("Results").Copy

targetBook = Application.GetOpenFilename("Excel files (*.xls*), *.xls*")


 If targetBook <> False Then
        Workbooks.Open (targetBook)
        Set targetBook = ActiveWorkbook

'            If Not Evaluate("isref(PP Import!a1)") Then
 '               MsgBox "The Selected Workbook does not contain a PP Import tab, check to validate the tab is named correctly or select a different Workbook"
 '           Exit Sub
'            Else
            


ActiveWorkbook.Sheets("PP Import").Range("A11").Select
 Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    
ActiveWorkbook.Sheets("PP Import").Range("C4").Value = Now()
ActiveWorkbook.Sheets("PP Import").Range("C5").FormulaR1C1 = "=MAX(R[11]C[46]:R[1000]C[46])"

ActiveWorkbook.Sheets("PP Import").Range("C5").Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False

Else

End If


End Sub

could it be that the workbook being opened is an xlsm? I have no clue why its not working any longer.

Thanks for the help.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
By adding: ActiveWorkbook.Sheets("PP Import").Activate I no longer get an error message.

Code:
Sub MoveReultsToTraker()


Dim sourceBook As Workbook
Dim targetBook As Variant
Dim sourceSheet As Worksheet
Dim targetSheet As Worksheet

Set sourceBook = ThisWorkbook
Set sourceSheet = sourceBook.Sheets("Results")

sourceSheet.Range("Results").Copy

targetBook = Application.GetOpenFilename("Excel files (*.xls*), *.xls*")


 If targetBook <> False Then
        Workbooks.Open (targetBook)
        Set targetBook = ActiveWorkbook

'            If Not Evaluate("isref(PP Import!a1)") Then
 '               MsgBox "The Selected Workbook does not contain a PP Import tab, check to validate the tab is named correctly or select a different Workbook"
 '           Exit Sub
'            Else
            
'Added this and error stopped
'******************************************************
ActiveWorkbook.Sheets("PP Import").Activate
'*******************************************************

ActiveWorkbook.Sheets("PP Import").Range("A11").Select
 Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    
ActiveWorkbook.Sheets("PP Import").Range("C4").Value = Now()
ActiveWorkbook.Sheets("PP Import").Range("C5").FormulaR1C1 = "=MAX(R[11]C[46]:R[1000]C[46])"

ActiveWorkbook.Sheets("PP Import").Range("C5").Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False

Else

End If


End Sub

Thanks
 
Upvote 0
Solution

Forum statistics

Threads
1,214,669
Messages
6,120,828
Members
448,990
Latest member
rohitsomani

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top