View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
K Dales[_2_] K Dales[_2_] is offline
external usenet poster
 
Posts: 1,163
Default VBA Beginner: Help with Checkboxes on created User Form

First part:
There are two options: checkboxes or a listbox with the MultiSelect property
set to fmMultiSelectExtended (this lets you select more than one listed
option, as you can in many Windows dialogs - holding ctrl lets you choose
more than one; holding shift lets you choose a range of consecutive choices).
The listbox is easier to implement bu not necessarily as user-friendly. The
checkboxes all have to be added and coded separately so it is a lot of
coding. To read them: For the list box:
' This fills a range beginning at A1 with the selected list items
For i = 1 to Listbox1.ListCount
If Listbox1.Selected(i) Then Range("A1").Offset(i-1,0)=Listbox1.List(i)
Next i

For checkboxes: (note the value is either True or False depending on whether
checked - so IF statement can just use the value)
If Checkbox1.Value Then Range("A1")="Box1 checked"
If Checkbox2.Value Then Range("A2")="Box2 checked"
etc...

These are just basic examples but hopefully show how to use the controls.
--
- K Dales


"MarianneR" wrote:


Hi. I'm basically teaching myself some VBA skills when I need them. So
please, bear with me.

I've created a user form for an Excel spreadsheet for fairly
inexperienced users. I have combo boxes and text boxes that work
perfectly well. However, I'm trying to add a check box and I guess
I'm not quite sure how they work. Is the checkbox more an individual
thing? Does it work in such a way that each item I want needs its own
checkbox?

My user form _might_ look something like this:

Patient Name: (text box)
Diagnosis: (combo box - list of 10)
CoMorbidities: (checkbox - list of 9 things, more than one can be
chosen)

Basically, I was wondering if it would be possible to have a checkbox
like this on a user form. Can I create something where you can select
more than one option and then have it drop into my spreadsheet? I keep
looking for this, but I'm not even aware if it's possible.

Another question I have is that if my a user closes the form without
clicking on the "enter data" or "close form" command buttons, a
"compile error" occurs. Here's the code that I have (from an example I
found):
Private Sub UserForm_Click()
(Cancel As Integer, _
CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "Please use the button!"
End If

The part in parenthesis turns red after the error.

Your patience and any help is appreciated. I hope I've provided enough
information.

Thank you in advance.
Marianne


--
MarianneR
------------------------------------------------------------------------
MarianneR's Profile: http://www.excelforum.com/member.php...fo&userid=6253
View this thread: http://www.excelforum.com/showthread...hreadid=475191