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
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Why not just put the code into a separate sub & then call it from both buttons?
 
Upvote 0
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
Why not just put the code into a separate sub & then call it from both buttons?
I need it to just be called from the CommandButton on Sheet1. I ran it from Sheet5 just to make sure the code works. I am new to VBA so not sure how to do certain code
 
Upvote 0
In that case get rid of the button on sheet5 & put the code into the button on sheet1
 
Upvote 0
In that case get rid of the button on sheet5 & put the code into the button on sheet1
The actually macro code i am using is listed below and not actually sure how to write this into the macro on Sheet1 with the CommandButton

VBA Code:
Option Explicit

Private Sub FilterColorToRed()
'
' FilterColorToRed12 Macro
'

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

End Sub
 
Upvote 0
How about
VBA Code:
Private Sub FilterColorToRed()
'
' FilterColorToRed12 Macro
'

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

End Sub
 
Upvote 0
How about
VBA Code:
Private Sub FilterColorToRed()
'
' FilterColorToRed12 Macro
'

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

End Sub
Is this in the CommandButton?
 
Upvote 0
You put the code in the command button click event.
 
Upvote 0

Forum statistics

Threads
1,214,812
Messages
6,121,704
Members
449,048
Latest member
81jamesacct

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