PDA

View Full Version : Calling Macro's



anusha
10-07-2005, 03:45 PM
I need help with two radio buttons...

The first one does a filter

The second a graph

What do I do to turn off filter and close the graph window?


Private Sub filter_Click()
Call percent
End Sub

Private Sub graphs_Click()
Call graph
End Sub

Here's the code...


Sub percent()
'
' percent Macro
' Macro recorded 10/7/2005 by M1AFD00

Range("A11:H2500").Select
Selection.AutoFilter
Selection.AutoFilter Field:=8, Criteria1:=">=100%", Operator:=xlOr, Criteria2:="<=-100%"
End Sub
Sub graph()
'
' graph Macro
' Macro recorded 10/7/2005 by M1AFD00
Range("G11").Select
Range(Selection, Selection.End(xlDown)).Select
Charts.Add
ActiveChart.ChartType = xlLineMarkers
ActiveChart.SetSourceData Source:=Sheets("ANALYSIS").Range("G11:G119"), _
PlotBy:=xlColumns
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(2).Values = "=ANALYSIS!R11C9:R119C9"
ActiveChart.Location Where:=xlLocationAsObject, Name:="ANALYSIS"
ActiveChart.HasLegend = False
ActiveChart.HasDataTable = False
End Sub

royUK
10-07-2005, 11:47 PM
Why not use a CommandButton instead, like this to perform two functions
Note the messageboxes are for demonstration only


'---------------------------------------------------------------------------------------
' Procedure : CommandButton1_Click
' DateTime : 08/10/2005 07:46
' Author : Roy Cox
' Purpose : Use Commandbutton for 2 commands
'---------------------------------------------------------------------------------------
'
Private Sub CommandButton1_Click()
Dim strChoice As String
strChoice = CommandButton1.Caption
Select Case strChoice
Case "On"
'call Percent
CommandButton1.Caption = "Off"
MsgBox "Filtering"
Case "Off"
MsgBox "Switching off"
'Selection.AutoFilter
CommandButton1.Caption = "On"
Case Else
Exit Sub
End Select
End Sub

Bob Phillips
10-08-2005, 07:55 AM
What do I do to turn off filter and close the graph window?


activesheet.cells.autofilter

does the filter.

Have you opened another window for the graph? If so it would be something like

windows("Book1:2").close

otherwise just select another sheet

Worksheets("Sheet1").Activate

.

malik641
10-08-2005, 08:24 AM
Hi anusha

Just a suggestion to make your code a little more efficient (and easier to read). Try using With/End With statements in your code, like so:

Sub graph()
'
' graph Macro
' Macro recorded 10/7/2005 by M1AFD00
Range("G11").Select
Range(Selection, Selection.End(xlDown)).Select
Charts.Add

With ActiveChart
.ChartType = xlLineMarkers
.SetSourceData Source:=Sheets("ANALYSIS").Range("G11:G119"), PlotBy:=xlColumns
.SeriesCollection.NewSeries
.SeriesCollection(2).Values = "=ANALYSIS!R11C9:R119C9"
.Location Where:=xlLocationAsObject, Name:="ANALYSIS"
.HasLegend = False
.HasDataTable = False
End With

End Sub
Hope you find this useful http://vbaexpress.com/forum/images/smilies/001.gif

anusha
10-08-2005, 07:31 PM
Hi and thanks for your response... I am bew to this stuff and don't know where to put this code... Help !!!


activesheet.cells.autofilter

does the filter. ------ call percent???

Have you opened another window for the graph? No. it is on the same sheet <----

windows("Book1:2").close

otherwise just select another sheet

Worksheets("Sheet1").Activate