Error with recorded macro

artz

Well-known Member
Joined
Aug 11, 2002
Messages
830
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I recorded the following macro with the macro recorder:
Code:
Sub Change_Worksheet()
    Sheets("Portfolio").Select
    Range("B2").Select
End Sub

It simply switches worksheets and and activates a cell. When I cal this sub from within another sub, I get the message: ' Select Method of Range Class failed'

Can Anyone in the Forum have a suggestion to modify the sub so that this error does not occur?

Thanks,

Art
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Thanks for your response, however, I get the same error message as with my sub when your sub is called.

Any other suggestions?

-Art
 
Upvote 0
Hi,

I recorded the following macro with the macro recorder:
Code:
Sub Change_Worksheet()
    Sheets("Portfolio").Select
    Range("B2").Select
End Sub

It simply switches worksheets and and activates a cell. When I cal this sub from within another sub, I get the message: ' Select Method of Range Class failed'

Can Anyone in the Forum have a suggestion to modify the sub so that this error does not occur?

Thanks,

Art

Seems to work fine for me...
 
Upvote 0
Domenic,

Thanks for your comments. I am curious as to why it works for you and I get an error when the sub is called.

Any thoughts?

Art
 
Upvote 0
just tried this

Sub callit()
Call Change_Worksheet
End Sub

and it works, do you have the underscore in the call?
 
Upvote 0
I was able to activate the new worksheet using:
Code:
    With Sheets("Portfolio")
    .Activate
    End With

-Art
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,909
Members
452,949
Latest member
beartooth91

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