CommandButton wont work calling another sheet

scubadivingfool

New Member
Joined
Jun 17, 2010
Messages
35
Looking at using a CommandButton on Sheet1 that calls a macro that I have in Sheet5. When I run the macro straight from Sheet5 it works perfectly, but when I run it from the CommandButton on Sheet1 nothing happens. The code is listed below that I am using in the CommandButton to call the maro in Sheet5. I have also tried the Code without the "Public" and just calling the Sub but sill nothing works.


VBA Code:
Public Sub FilterColorToRed()

Call Sheets("Sheet5").CommandButton3_Click
   
End Sub
 
You put the code in the command button click event.
Like in the following? I get an error code of "Expected End Sum"


VBA Code:
Private Sub CommandButton3_Click()
   

 Private Sub FilterColorToRed()
'
' FilterColorToRed12 Macro
'

'
   
    Sheets("Sheet5").Range("$A$1:$G$634").AutoFilter Field:=1, Criteria1:=RGB(255, 0 _
        , 0), Operator:=xlFilterCellColor

 End Sub


End Sub
 
Upvote 0

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Delete this line Private Sub FilterColorToRed() and one of the two End Sub
 
Upvote 0
Delete this line Private Sub FilterColorToRed() and one of the two End Sub
Now when I run the code I get a "Subscript out of range" error

1640538893815.png
 
Upvote 0
Do you actually have a sheet called Sheet5?
 
Upvote 0
Do you actually have a sheet called Sheet5?
Yes, Sheet 5 contains infomation that has colored cells. What I need is to filter out all the colors except for the red ones. The Sheet has been renamed to "PriceChange", but Sheet5 is still the primary name
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,620
Messages
6,120,554
Members
448,970
Latest member
kennimack

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