garyj
07-16-2024, 06:03 PM
Hello..
I created my own Excel dropdown and thought I'd share it here. Feedback is good.
The data validation has very small text that cannot be edited. Same is true for the user form dropdown. I believe the Active X dropdown font size can be modified, but Active X comes with another set of problems. So, after some thought, I figured I would see how hard it could be to make my own. Perhaps it's been done before, but my research did not find anything. Here it is.
I began by making a textbox on the worksheet. All this can be done by code, but I did it with the Excel menu commands.
- Menu: Insert / Text Box (1st one in list); click on spreadsheet, type random text "Boo", size as desired, select font and size..
- Copy and paste 4 more text boxes.
- While a text box still selected, Menu: Shape Format / Selection Pane; I used this to rename them TB1 thru TB5. Can also be used to select/deselect or hide/unhide.
- I then manually stacked them one below the other, and aligned them, and grouped them, naming the group "DpDn1", and giving it a border.
- I then did a screen copy of a drop down button, and pasted it to the sheet, placing it on top of DpDn1 at top right corner.
- It looks like this.. and obviously the random text has nothing to do with the Method of Payment haha.
31713
Coding is as follows:
Two macros created in a module: the first is attached to the dropdown arrow picture, so when it is clicked the dropdown opens. The second is attached to each of the 5 textboxes, so that no matter which is selected the SelectTB runs. MyStr = the text in the box selected, and of course could be manipulated to do whatever from there.
Follows the code inserted into Sheet4 code under selection change as the first line to close the dropdown in case nothing is selected after the dropdown pic is selected.
Sub SelectDrpDwn()
Sheet4.shapes("DpDn1").Visible = msoTrue
End Sub
Sub SelectTB()
Dim myStr As String
myStr = Application.Caller
Sheet4.shapes("DpDn1").Visible = msoFalse
Application.ScreenUpdating = True
MsgBox Sheet4.shapes(myStr).TextFrame.Characters.Text
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Sheet4.shapes("DpDn1").Visible = msoFalse
I was not able to find a way to change background of textbox on mouseover, but I don't know how necessary that is.
That's it folks. A dropdown made without lots of code, and it works.
Gary
I created my own Excel dropdown and thought I'd share it here. Feedback is good.
The data validation has very small text that cannot be edited. Same is true for the user form dropdown. I believe the Active X dropdown font size can be modified, but Active X comes with another set of problems. So, after some thought, I figured I would see how hard it could be to make my own. Perhaps it's been done before, but my research did not find anything. Here it is.
I began by making a textbox on the worksheet. All this can be done by code, but I did it with the Excel menu commands.
- Menu: Insert / Text Box (1st one in list); click on spreadsheet, type random text "Boo", size as desired, select font and size..
- Copy and paste 4 more text boxes.
- While a text box still selected, Menu: Shape Format / Selection Pane; I used this to rename them TB1 thru TB5. Can also be used to select/deselect or hide/unhide.
- I then manually stacked them one below the other, and aligned them, and grouped them, naming the group "DpDn1", and giving it a border.
- I then did a screen copy of a drop down button, and pasted it to the sheet, placing it on top of DpDn1 at top right corner.
- It looks like this.. and obviously the random text has nothing to do with the Method of Payment haha.
31713
Coding is as follows:
Two macros created in a module: the first is attached to the dropdown arrow picture, so when it is clicked the dropdown opens. The second is attached to each of the 5 textboxes, so that no matter which is selected the SelectTB runs. MyStr = the text in the box selected, and of course could be manipulated to do whatever from there.
Follows the code inserted into Sheet4 code under selection change as the first line to close the dropdown in case nothing is selected after the dropdown pic is selected.
Sub SelectDrpDwn()
Sheet4.shapes("DpDn1").Visible = msoTrue
End Sub
Sub SelectTB()
Dim myStr As String
myStr = Application.Caller
Sheet4.shapes("DpDn1").Visible = msoFalse
Application.ScreenUpdating = True
MsgBox Sheet4.shapes(myStr).TextFrame.Characters.Text
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Sheet4.shapes("DpDn1").Visible = msoFalse
I was not able to find a way to change background of textbox on mouseover, but I don't know how necessary that is.
That's it folks. A dropdown made without lots of code, and it works.
Gary