VBA Run-Time Error 1004

pip74205

New Member
Joined
Feb 7, 2017
Messages
16
I'm trying to fix a macro that removes the formulas on a specific tab. When I run it, I get the following error displayed: "Run-time error '1004': Select method of Range class failed".
Any idea what I am missing? Also, what would I need to add to the end to have the macro end in cell A1 on the "Manager Summary" tab?

Thanks a lot for any help you can provide.

Sub RemoveFormulas()
'
' RemoveFormulas Macro
'
With Worksheets("Report")
.Cells.Copy
.Cells.PasteSpecial xlPasteValues
.Cells(1).Select
End With
'
End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
I imagine the error is for the .Cells(1).Select part and I also assume that you ran this while a different sheet was active. I'm not sure why you are trying to use select there, but the reason you are getting this error is because you simply cannot select a range in an object that isn't active.

Code:
Worksheets("Report").Activate

Adding that right above the select line would fix it. If you want to end the macro in cell A1 of a different sheet, then the code would look something like this:

Code:
Sub RemoveFormulas()
'
'RemoveFormulas Macro
'
With Worksheets("Report")
.Cells.Copy
.Cells.PasteSpecial xlPasteValues
End With

Worksheets("Manager Summary").Activate
Worksheets("Manager Summary").Cells(1).Select

End Sub
 
Last edited:
Upvote 0
How about
Code:
Sub RemoveFormulas()
'
' RemoveFormulas Macro
'
With Worksheets("Report").UsedRange
   .Value = .Value
End With
Sheets("Manager Summary").Select
Range("A1").Select
End Sub
You would have received the error if the Report sheet was not the active sheet when you ran the macro
 
Upvote 0
How about
Code:
Sub RemoveFormulas()
'
' RemoveFormulas Macro
'
With Worksheets("Report").UsedRange
   .Value = .Value
End With
Sheets("Manager Summary").Select
Range("A1").Select
End Sub
You would have received the error if the Report sheet was not the active sheet when you ran the macro

Thank you! This removed the run-time error. However, the data on the Report tab was formatted as a table. This macro removed that. Is it possible to keep the data as a table?
 
Upvote 0
How about
Code:
Sub RemoveFormulas()
'
' RemoveFormulas Macro
'
With Worksheets("Report").ListObjects("[COLOR=#ff0000]Table2[/COLOR]").DataBodyRange
   .Value = .Value
End With
Sheets("Manager Summary").Select
Range("A1").Select
End Sub
Change table name to suit
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,550
Members
449,088
Latest member
davidcom

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