adjust this code ???

d0wnt0wn

Well-known Member
Joined
Oct 28, 2002
Messages
771
hi i have the following fantastic code supplied by Norie..... it does very nearly exactly what i want except for a couple of things... firstly how do adjust the code to create the team list in the combobox from a list on a worksheet? from what I can gather from the code this is the part that creates the current list that i have

{ For I = 1 To 24
cmdbarcombo.AddItem "Team" & I
Next I
}

is that correct???

Sub CreateCustomToolbar()
Dim cmdbar As CommandBar
Dim cmdbarcombo As CommandBarComboBox
Dim cmdbarbtn As CommandBarButton
Dim I As Integer

Set cmdbar = CommandBars.Add(Name:="Colour Teams")

Set cmdbarcombo = cmdbar.Controls.Add(msoControlComboBox)

cmdbarcombo.Tag = "TeamCombo"

cmdbarcombo_OnAction = "ChangeColour"

Set cmdbarbtn = cmdbar.Controls.Add(msoControlButton)

cmdbarbtn.Caption = "Team Colour"

cmdbarbtn.Tag = "TeamColour"

cmdbarbtn.Style = msoButtonCaption

Set cmdbarbtn = cmdbar.Controls.Add(msoControlButton)

cmdbarbtn.Caption = "Colour Cells"

cmdbarbtn.Style = msoButtonCaption

cmdbarbtn.OnAction = "ColourCells"
For I = 1 To 24
cmdbarcombo.AddItem "Team" & I
Next I

cmdbarcombo.ListIndex = 1

cmdbar.Visible = True

End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
tony any idea how i would adjust that so that the list populates based on a range on my worksheet instead?
 
Upvote 0
Try this:
Code:
For I = 1 To 24
    cmdbarcombo.AddItem Worksheets("Sheet3").Range("A" & I)
Next I
 
Upvote 0
hmmm for some reason im getting an error now even before i change that bit of code norie....

run time error 5 invalid procedure call or argument at this line

Set cmdbar = CommandBars.Add(Name:="Colour Teams")





Sub CreateCustomToolbar()
Dim cmdbar As CommandBar
Dim cmdbarcombo As CommandBarComboBox
Dim cmdbarbtn As CommandBarButton
Dim I As Integer

Set cmdbar = CommandBars.Add(Name:="Colour Teams")

Set cmdbarcombo = cmdbar.Controls.Add(msoControlComboBox)

cmdbarcombo.Tag = "TeamCombo"

cmdbarcombo_OnAction = "ChangeColour"

Set cmdbarbtn = cmdbar.Controls.Add(msoControlButton)

cmdbarbtn.Caption = "Team Colour"

cmdbarbtn.Tag = "TeamColour"

cmdbarbtn.Style = msoButtonCaption

Set cmdbarbtn = cmdbar.Controls.Add(msoControlButton)

cmdbarbtn.Caption = "Colour Cells"

cmdbarbtn.Style = msoButtonCaption

cmdbarbtn.OnAction = "ColourCells"
For I = 1 To 24
cmdbarcombo.AddItem "Team" & I
Next I

cmdbarcombo.ListIndex = 1

cmdbar.Visible = True

End Sub

Sub DeleteCustomToolbar()
CommandBars("Colour Teams").Delete
End Sub

Sub ChangeColour()
Dim cmdcombo As CommandBarComboBox
Dim cmdbtn As CommandBarButton

Set cmdcombo = CommandBars("Colour Teams").FindControl(, , "TeamCombo")
Set cmdbtn = CommandBars("Colour Teams").FindControl(, , "TeamColour")

cmdbtn.Caption = "Colour" & cmdcombo.ListIndex

End Sub

Sub ColourCells()
Dim cmdcombo As CommandBarComboBox
Dim rng As Range

Set cmdcombo = CommandBars("Colour Teams").FindControl(, , "TeamCombo")

Set rng = Selection

rng.Interior.ColorIndex = cmdcombo.ListIndex
End Sub
 
Upvote 0
You are probably getting that error because the toolbar already exists.
 
Upvote 0
yes thats what happened I went and deleted all of the test macros i had made on different sheets and it worked..... is there any way i can make the combobox a bit wider???
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,022
Members
448,939
Latest member
Leon Leenders

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