Hi all,
This is my first post here and I have only be playing with code for a week so be gentle.
I have manage to create a monster. I have 28 buttons for 28 pieces of equipment. I have 31 specifications that need to be displayed in 31 line charts for each piece of equipment. As you can imagine a little bit of typing and glad I know how to cut and paste.
The code works. Each button calls a macro and changes the colour of the button so you know which one is selected. I won't bable on anymore and will post the code.
![]()
Sub MacroDG1() ' ' MacroDG1 Macro ' ' ActiveSheet.ChartObjects("Chart 1").Activate ActiveChart.SeriesCollection(1).Select ActiveChart.SetSourceData Source:=Sheets("DG # 1").Range("A8:U8") ActiveChart.SeriesCollection(1).XValues = "='DG # 1'!$B$2:$U$2" ActiveSheet.ChartObjects("Chart 2").Activate ActiveChart.SeriesCollection(1).Select ActiveChart.SetSourceData Source:=Sheets("DG # 1").Range("A9:U9") ActiveChart.SeriesCollection(1).XValues = "='DG # 1'!$B$2:$U$2" ActiveSheet.ChartObjects("Chart 3").Activate ActiveChart.SeriesCollection(1).Select ActiveChart.SetSourceData Source:=Sheets("DG # 1").Range("A11:U11") ActiveChart.SeriesCollection(1).XValues = "='DG # 1'!$B$2:$U$2" ActiveSheet.ChartObjects("Chart 4").Activate ActiveChart.SeriesCollection(1).Select ActiveChart.SetSourceData Source:=Sheets("DG # 1").Range("A12:U12") ActiveChart.SeriesCollection(1).XValues = "='DG # 1'!$B$2:$U$2" ActiveSheet.ChartObjects("Chart 5").Activate ActiveChart.SeriesCollection(1).Select ActiveChart.SetSourceData Source:=Sheets("DG # 1").Range("A13:U13") ActiveChart.SeriesCollection(1).XValues = "='DG # 1'!$B$2:$U$2" ActiveSheet.ChartObjects("Chart 6").Activate ActiveChart.SeriesCollection(1).Select ActiveChart.SetSourceData Source:=Sheets("DG # 1").Range("A14:U14") ActiveChart.SeriesCollection(1).XValues = "='DG # 1'!$B$2:$U$2" ActiveSheet.ChartObjects("Chart 7").Activate ActiveChart.SeriesCollection(1).Select ActiveChart.SetSourceData Source:=Sheets("DG # 1").Range("A15:U15") ActiveChart.SeriesCollection(1).XValues = "='DG # 1'!$B$2:$U$2" ActiveSheet.ChartObjects("Chart 8").Activate ActiveChart.SeriesCollection(1).Select ActiveChart.SetSourceData Source:=Sheets("DG # 1").Range("A17:U17") ActiveChart.SeriesCollection(1).XValues = "='DG # 1'!$B$2:$U$2" ActiveSheet.ChartObjects("Chart 9").Activate ActiveChart.SeriesCollection(1).Select ActiveChart.SetSourceData Source:=Sheets("DG # 1").Range("A23:U23") ActiveChart.SeriesCollection(1).XValues = "='DG # 1'!$B$2:$U$2" ActiveSheet.ChartObjects("Chart 10").Activate ActiveChart.SeriesCollection(1).Select ActiveChart.SetSourceData Source:=Sheets("DG # 1").Range("A28:U28") ActiveChart.SeriesCollection(1).XValues = "='DG # 1'!$B$2:$U$2" ActiveSheet.ChartObjects("Chart 11").Activate ActiveChart.SeriesCollection(1).Select ActiveChart.SetSourceData Source:=Sheets("DG # 1").Range("A29:U29") ActiveChart.SeriesCollection(1).XValues = "='DG # 1'!$B$2:$U$2" ActiveSheet.ChartObjects("Chart 12").Activate ActiveChart.SeriesCollection(1).Select ActiveChart.SetSourceData Source:=Sheets("DG # 1").Range("A30:U30") ActiveChart.SeriesCollection(1).XValues = "='DG # 1'!$B$2:$U$2" ActiveSheet.ChartObjects("Chart 13").Activate ActiveChart.SeriesCollection(1).Select ActiveChart.SetSourceData Source:=Sheets("DG # 1").Range("A31:U31") ActiveChart.SeriesCollection(1).XValues = "='DG # 1'!$B$2:$U$2" ActiveSheet.ChartObjects("Chart 14").Activate ActiveChart.SeriesCollection(1).Select ActiveChart.SetSourceData Source:=Sheets("DG # 1").Range("A32:U32") ActiveChart.SeriesCollection(1).XValues = "='DG # 1'!$B$2:$U$2" ActiveSheet.ChartObjects("Chart 15").Activate ActiveChart.SeriesCollection(1).Select ActiveChart.SetSourceData Source:=Sheets("DG # 1").Range("A33:U33") ActiveChart.SeriesCollection(1).XValues = "='DG # 1'!$B$2:$U$2" ActiveSheet.ChartObjects("Chart 16").Activate ActiveChart.SeriesCollection(1).Select ActiveChart.SetSourceData Source:=Sheets("DG # 1").Range("A34:U34") ActiveChart.SeriesCollection(1).XValues = "='DG # 1'!$B$2:$U$2" ActiveSheet.ChartObjects("Chart 17").Activate ActiveChart.SeriesCollection(1).Select ActiveChart.SetSourceData Source:=Sheets("DG # 1").Range("A35:U35") ActiveChart.SeriesCollection(1).XValues = "='DG # 1'!$B$2:$U$2" ActiveSheet.ChartObjects("Chart 18").Activate ActiveChart.SeriesCollection(1).Select ActiveChart.SetSourceData Source:=Sheets("DG # 1").Range("A36:U36") ActiveChart.SeriesCollection(1).XValues = "='DG # 1'!$B$2:$U$2" ActiveSheet.ChartObjects("Chart 19").Activate ActiveChart.SeriesCollection(1).Select ActiveChart.SetSourceData Source:=Sheets("DG # 1").Range("A37:U37") ActiveChart.SeriesCollection(1).XValues = "='DG # 1'!$B$2:$U$2" ActiveSheet.ChartObjects("Chart 20").Activate ActiveChart.SeriesCollection(1).Select ActiveChart.SetSourceData Source:=Sheets("DG # 1").Range("A39:U39") ActiveChart.SeriesCollection(1).XValues = "='DG # 1'!$B$2:$U$2" ActiveSheet.ChartObjects("Chart 21").Activate ActiveChart.SeriesCollection(1).Select ActiveChart.SetSourceData Source:=Sheets("DG # 1").Range("A40:U40") ActiveChart.SeriesCollection(1).XValues = "='DG # 1'!$B$2:$U$2" ActiveSheet.ChartObjects("Chart 22").Activate ActiveChart.SeriesCollection(1).Select ActiveChart.SetSourceData Source:=Sheets("DG # 1").Range("A41:U41") ActiveChart.SeriesCollection(1).XValues = "='DG # 1'!$B$2:$U$2" ActiveSheet.ChartObjects("Chart 23").Activate ActiveChart.SeriesCollection(1).Select ActiveChart.SetSourceData Source:=Sheets("DG # 1").Range("A44:U44") ActiveChart.SeriesCollection(1).XValues = "='DG # 1'!$B$2:$U$2" ActiveSheet.ChartObjects("Chart 24").Activate ActiveChart.SeriesCollection(1).Select ActiveChart.SetSourceData Source:=Sheets("DG # 1").Range("A45:U45") ActiveChart.SeriesCollection(1).XValues = "='DG # 1'!$B$2:$U$2" ActiveSheet.ChartObjects("Chart 25").Activate ActiveChart.SeriesCollection(1).Select ActiveChart.SetSourceData Source:=Sheets("DG # 1").Range("A46:U46") ActiveChart.SeriesCollection(1).XValues = "='DG # 1'!$B$2:$U$2" ActiveSheet.ChartObjects("Chart 26").Activate ActiveChart.SeriesCollection(1).Select ActiveChart.SetSourceData Source:=Sheets("DG # 1").Range("A47:U47") ActiveChart.SeriesCollection(1).XValues = "='DG # 1'!$B$2:$U$2" ActiveSheet.ChartObjects("Chart 27").Activate ActiveChart.SeriesCollection(1).Select ActiveChart.SetSourceData Source:=Sheets("DG # 1").Range("A48:U48") ActiveChart.SeriesCollection(1).XValues = "='DG # 1'!$B$2:$U$2" ActiveSheet.ChartObjects("Chart 28").Activate ActiveChart.SeriesCollection(1).Select ActiveChart.SetSourceData Source:=Sheets("DG # 1").Range("A49:U49") ActiveChart.SeriesCollection(1).XValues = "='DG # 1'!$B$2:$U$2" ActiveSheet.ChartObjects("Chart 29").Activate ActiveChart.SeriesCollection(1).Select ActiveChart.SetSourceData Source:=Sheets("DG # 1").Range("A57:U57") ActiveChart.SeriesCollection(1).XValues = "='DG # 1'!$B$2:$U$2" ActiveSheet.ChartObjects("Chart 30").Activate ActiveChart.SeriesCollection(1).Select ActiveChart.SetSourceData Source:=Sheets("DG # 1").Range("A58:U58") ActiveChart.SeriesCollection(1).XValues = "='DG # 1'!$B$2:$U$2" ActiveSheet.ChartObjects("Chart 31").Activate ActiveChart.SeriesCollection(1).Select ActiveChart.SetSourceData Source:=Sheets("DG # 1").Range("A59:U59") ActiveChart.SeriesCollection(1).XValues = "='DG # 1'!$B$2:$U$2" End Sub
This one of the 28 macros dumping data from sheet DG # 1 into each chart.
This is the code that calls a macro and changes the colour of the buttons![]()
Private Sub CommandButton2_Click() Call MacroDG1 ActiveSheet.CommandButton1.BackColor = &H8000000F 'grey ActiveSheet.CommandButton2.BackColor = &H80000010 'dark grey ActiveSheet.CommandButton3.BackColor = &H8000000F 'grey ActiveSheet.CommandButton4.BackColor = &H8000000F 'grey ActiveSheet.CommandButton5.BackColor = &H8000000F 'grey ActiveSheet.CommandButton6.BackColor = &H8000000F 'grey ActiveSheet.CommandButton7.BackColor = &H8000000F 'grey ActiveSheet.CommandButton8.BackColor = &H8000000F 'grey ActiveSheet.CommandButton9.BackColor = &H8000000F 'grey ActiveSheet.CommandButton10.BackColor = &H8000000F 'grey ActiveSheet.CommandButton11.BackColor = &H8000000F 'grey ActiveSheet.CommandButton12.BackColor = &H8000000F 'grey ActiveSheet.CommandButton13.BackColor = &H8000000F 'grey ActiveSheet.CommandButton14.BackColor = &H8000000F 'grey ActiveSheet.CommandButton15.BackColor = &H8000000F 'grey ActiveSheet.CommandButton16.BackColor = &H8000000F 'grey ActiveSheet.CommandButton17.BackColor = &H8000000F 'grey ActiveSheet.CommandButton18.BackColor = &H8000000F 'grey ActiveSheet.CommandButton19.BackColor = &H8000000F 'grey ActiveSheet.CommandButton20.BackColor = &H8000000F 'grey ActiveSheet.CommandButton21.BackColor = &H8000000F 'grey ActiveSheet.CommandButton22.BackColor = &H8000000F 'grey ActiveSheet.CommandButton23.BackColor = &H8000000F 'grey ActiveSheet.CommandButton24.BackColor = &H8000000F 'grey ActiveSheet.CommandButton25.BackColor = &H8000000F 'grey ActiveSheet.CommandButton26.BackColor = &H8000000F 'grey ActiveSheet.CommandButton27.BackColor = &H8000000F 'grey ActiveSheet.CommandButton28.BackColor = &H8000000F 'grey End Sub
This where the fun starts. In the range comments below the cells U8 and U$2 may be different for each piece of equipment, It is determined by the number of test sample taken/recorded. So the "U" may be an "M" or a "K" but for each of the 31 specs it will be the same.
Range("A8:U8") (This cell location range has data in it.)
"='DG # 1'!$B$2:$U$2" (This cell location range has dates in it. Possibly you could examine cells B2 to ??2 to see if it contains a date, not sure if this can be done, as soon as a cell doesn't have a date go back one and use it. This cell letter would also need to be applied to the data range as well.)
Is there a way I can do an If/Case type of look up? At the moment this sort of thing is way above me so any help would be greatly appreciated.
Bookmarks