I have a worksheet in which the user needs to enter numeric values in a column. The numeric values represent a certain type of something. EX: 0 would equal Credit and 1 would equal debit. What I would like is to use a combo box in the cell that lists Credit and Debit as the choices but enters in that cells value the numeric equivalent.
![]() |
Patch reliability is unclear, but widespread attacks make patching prudent. Go ahead and patch, but watch out for potential problems. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Using a combo box to enter a cell value (2000)
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Using a combo box to enter a cell value (2000)
- This topic has 10 replies, 4 voices, and was last updated 22 years, 11 months ago.
Viewing 0 reply threadsAuthorReplies-
WSAndrew Cronnolly
AskWoody LoungerJuly 9, 2002 at 1:00 pm #599942If you have a ComboBox named ComboBox1 (from the Control Toolbox) then the following code might help
Private Sub ComboBox1_Change()
Range(“A1”).Value = Me.ComboBox1.ListIndex
End SubWhere A1 is the cell you want to fill. If your ComboBox has a LinkedCell value, remove it.
Just right click on the appropriate Sheet tab, select View Code, and enter the above code in the codepane.
Andrew C
-
edcarden
AskWoody LoungerJuly 9, 2002 at 2:08 pm #599960Thanks for the info. Now another Q. This is the first time I’ve tried using a combobox in Excel and I can’t figure what property to set for the values in the combobox. In VB this would be the rowsourse.
Also. If I want this same type of control to appear over ever row in this column when the user selects a cell in that column how would I do so?
-
WSAndrew Cronnolly
AskWoody LoungerJuly 9, 2002 at 9:34 pm #600086To set the source for a worksheet combobox, you use the ListFillRange. To access the properties of the selected control click on the second icon from the left on the Control Toolbox. The first icon is a toggle (design/run) which when depressed allows you set the properties etc of the controls.
I think you might be better off using the Data Validation function rather than using a ComboBox for you current requirements. See attached workbook with the Data Validation coupled with some Worksheet_Change event code.
Andrew C
-
H. Legare Coleman
AskWoody PlusJuly 9, 2002 at 9:15 pm #600094One small suggestion. If you change the Change Event routine as below, you will save a little overhead by only executing the routine once for each change instead of twice.
Private Sub Worksheet_Change(ByVal Target As Range) Dim oCell As Range Set oCell = Target.Cells(1) Application.EnableEvents = False If Not Intersect(oCell, Range("D:D")) Is Nothing Then Select Case oCell.Value Case Is = "Credit" oCell = 0 Case Is = "Debit" oCell = 1 End Select End If Application.EnableEvents = True End Sub
-
WSAndrew Cronnolly
AskWoody Lounger -
WSfburg
AskWoody LoungerJuly 10, 2002 at 11:43 am #600242Andrew,
I was interested in this problem so I downloaded your sample spreadsheet. 2 questions:
1. Did you change your attachment to reflect what Legare mentioned about toggling the events? I couldn’t find any difference between the code in your workbook (both the version in the textbox on the worksheet and in the VBE) and Legare’s posted code.
2. It didn’t run in Excel 97. When I chose an item from the listbox, I got that value and not 0 or 1. The code looks pretty straightforward except for one thing: why do you set EnableEvents=False? Doesn’t this stop the sub from running due to a change in the workbook (like reselecting a cell in D1 and changing the value from the dropdown)? Even if I commented that line out, I still got the same result (the word, not the number).
TIA
Fred
-
WSfburg
AskWoody LoungerJuly 10, 2002 at 11:57 am #600245Andrew,
I think I answered part of my own question 2. I guess the EnableEvents=False prevents the worksheet_change from running a 2nd time (Legare’s point) when the code executes one of the oCell= statements. However, the code still doesn’t run in Excel 97 even tho 97 does seem to support a worksheet_change event. I put a msgbox in your sub right after the Dim stmt and even set a breakpoint. I went back and altered one of the cells and nothing seemed to be triggered in the code to stop (no break, no msgbox).
Fred
-
WSAndrew Cronnolly
AskWoody LoungerJuly 10, 2002 at 12:35 pm #600260Fred,
Would it be possible that on your System, EnableEvents are set to False. In the immediate window type Application.EnableEvents = True hit return and try again.
I did indeed edit the attachment to incorporate Legare’s suggestion, as I figured that ecarden had not yet downloaded it.
Andrew
-
WSAndrew Cronnolly
AskWoody LoungerJuly 10, 2002 at 5:40 pm #600353 -
WSfburg
AskWoody LoungerJuly 11, 2002 at 12:18 am #600412Andrew,
I think we have the whole story now.
EnableEvents was already true per the immediate window.
Seems DV does NOT trigger Worksheet_Change, as you guessed.
Moreover, if you type the item, you have to make sure you obey the case of the letter in the Select Case statement.
There is also a Worksheet_SelectionChange event. I observed the following behvior with your same code in that event sub:
-click on a cell in col D
-the event sub runs but nothing happens since the cell is empty (assume it is)
– now click the drop-down and make your selection
– now click on another cell
– click back on the cell you just were working in
Result is that your choice of “Credit” or “Debit” from the 3rd dash is converted to 0 or 1. So if there was a way to know what cell you came from, which does NOT appear to be an argument in this event, you’d be able to have the workaround. Since this doesn’t seem possible, I give up.Fred
-
-
-
-
Viewing 0 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Microsoft : Free 1 year support for Windows 10 after EOL
by
Alex5723
5 minutes ago -
MS-DEFCON 3: Businesses must tread carefully
by
Susan Bradley
58 minutes ago -
McLaren Health Care says data breach impacts 743,000 patients
by
Nibbled To Death By Ducks
10 hours, 50 minutes ago -
WhatsApp banned on House staffers’ devices
by
Alex5723
5 hours, 52 minutes ago -
Is your device eligible?
by
Susan Bradley
13 hours, 49 minutes ago -
Windows 11 Insider Preview build 26200.5661 released to DEV
by
joep517
20 hours ago -
Windows 11 Insider Preview build 26120.4452 (24H2) released to BETA
by
joep517
20 hours, 2 minutes ago -
Hello Windows…My Problem is Windows Hello…
by
rdleib
21 hours, 17 minutes ago -
New Canon Printer Wants Data Sent
by
Win7and10
21 hours, 35 minutes ago -
I set up passkeys for my Microsoft account
by
Lance Whitney
11 hours, 5 minutes ago -
AI is for everyone
by
Peter Deegan
21 hours, 8 minutes ago -
Terabyte update 2025
by
Will Fastie
15 hours, 11 minutes ago -
Migrating from Windows 10 to Windows 11
by
Susan Bradley
41 minutes ago -
Lost sound after the upgrade to 24H2?
by
Susan Bradley
1 day, 20 hours ago -
How to move 10GB of data in C:\ProgramData\Package Cache ?
by
Alex5723
51 minutes ago -
Plugged in 24-7
by
CWBillow
1 day, 6 hours ago -
Netflix, Apple, BofA websites hijacked with fake help-desk numbers
by
Nibbled To Death By Ducks
2 days, 9 hours ago -
Have Copilot there but not taking over the screen in Word
by
CWBillow
2 days, 6 hours ago -
Windows 11 blocks Chrome 137.0.7151.68, 137.0.7151.69
by
Alex5723
4 days ago -
Are Macs immune?
by
Susan Bradley
16 hours, 11 minutes ago -
HP Envy and the Function keys
by
CWBillow
3 days, 8 hours ago -
Microsoft : Removal of unwanted drivers from Windows Update
by
Alex5723
1 day, 1 hour ago -
MacOS 26 beta 1 dropped support for Firewire 400/800
by
Alex5723
4 days, 12 hours ago -
Unable to update to version 22h2
by
04om
1 day, 20 hours ago -
Windows 11 Insider Preview Build 26100.4482 (24H2) released to Release Preview
by
joep517
4 days, 19 hours ago -
Windows 11 Insider Preview build 27881 released to Canary
by
joep517
4 days, 19 hours ago -
Very Quarrelsome Taskbar!
by
CWBillow
4 days, 5 hours ago -
Move OneNote Notebook OFF OneDrive and make it local
by
CWBillow
5 days, 8 hours ago -
Microsoft 365 to block file access via legacy auth protocols by default
by
Alex5723
4 days, 21 hours ago -
Is your battery draining?
by
Susan Bradley
1 day, 3 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.