|
|
Question : Highlight Command Button to Show Active
|
|
Experts,
Been working on a Pivot table and command buttons to display different views. Is there a way I can re-color the button that was just pressed, the the user knows which view was selected (it is not always obvious) or a way to bring up a messagebox to 'cancel' the button and say "You are on the TurnOver View" (or something like that?).
Here is my code for one of my buttons. The rest are similiar, with different views:
Private Sub cmdYTDVar_Click() On Error Resume Next
Dim pt As PivotTable Dim ws As Workbooks Set ws = Me For Each pt In Me.PivotTables pt.TableRange2.Clear Next
Dim PivotT As PivotTable Dim ptName$ ptName = Me.Name Set PivotT = Me.PivotTableWizard(SourceType:=xlDatabase, _ SourceData:="RawData!R1C1:R9300C17", TableDestination:="R1C1", _ TableName:="ptName") ActiveWorkbook.ShowPivotTableFieldList = False With PivotT .PivotFields("Sales").Orientation = xlDataField .DataFields(1).NumberFormat = "$#,##0_);$#,##0)" .PivotFields("Distributor").Orientation = xlRowField .PivotFields("Month").Orientation = xlColumnField .PivotFields("BusinessUnit").Orientation = xlPageField .PivotFields("IndCode").Orientation = xlPageField .PivotFields("MonthsAsCustomer").Orientation = xlPageField .PivotFields("TurnOverDate").Orientation = xlPageField .PivotFields("TurnOver?").Orientation = xlPageField .PivotFields("Months12").Orientation = xlPageField .PivotFields("Months24").Orientation = xlPageField .PivotFields("YTDSalesY1").Orientation = xlPageField .PivotFields("YTDSalesY2").Orientation = xlPageField .PivotFields("Customer").Orientation = xlPageField .PivotFields("City").Orientation = xlPageField .PivotFields("State").Orientation = xlPageField .PivotFields("Lbs").Orientation = xlPageField .PivotFields("ProductName").Orientation = xlPageField End With [b16].Group Start:=True, End:=True, Periods:=Array(False, _ False, False, False, True, False, True) PivotT.PageFields("Months").Orientation = xlColumnField PivotT.PivotFields("Years").Orientation = xlPageField PivotT.PivotFields("Years").CurrentPage = "2004" End Sub
thanks in advance, AliciaVee
|
Answer : Highlight Command Button to Show Active
|
|
Here is an example from a userform with 3 commandbuttons. The basic idea is to color the "clicked" button and to reset the other buttons.
Private Sub CommandButton1_Click() CommandButton1.BackColor = vbRed CommandButton2.BackColor = &H8000000F CommandButton3.BackColor = &H8000000F End Sub
Private Sub CommandButton2_Click() CommandButton1.BackColor = &H8000000F CommandButton2.BackColor = vbRed CommandButton3.BackColor = &H8000000F End Sub
Private Sub CommandButton3_Click() CommandButton1.BackColor = &H8000000F CommandButton2.BackColor = &H8000000F CommandButton3.BackColor = vbRed End Sub
Claus Henriksen
|
|
|
|
|