View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
atpgroups atpgroups is offline
external usenet poster
 
Posts: 40
Default auto add to list

On 19 May, 16:19, Gizmo wrote:
ModSN is a named range. Refers to is
"=OFFSET(Lists!$H$9,0,0,CountA(Lists!$H:$H),1) ".
cbModSN is the ComboBox on form "frmProcessDataEntry". It's Row Source is
ModSN.


I confess that I didn't read your original message with the care I
should have done.
If you are trying to do what i think you are tryig to do, you want to
have a userform that you type things in to, and have that data added
to a worksheet column?
The problem with what you were doing is that the "Change" event isn't
relevant to a userform or a combobox. If you look at the top of the
code entry window you wll see two drop-down boxes, the left hand one
is all the objects you have available, and the right hand one shows
all the events that can be raised by the object. (in this case the
UserForm and the Combobox are objects).
Furthermore the "Target" range is only relevant to worksheet objects.
If you pick your events from the code window drop-downs you will get a
pre-formatted bit of code with correctly listed parameters.

What you probably want to do is trap the pressing of the "Enter" key
in the combobox. Every key press raises 3 events (KeyDown, KeyUp and
Keypress). Generally you want to ignore them.

This bit of code will do what I describe, it might not do what you
want (I am not clear if you are ising the ModSN range for anything.
Paste this in your userform
(note that the Google Groups interface tends to put in spurious line-
breaks, so some fiddling might be required)

Private Sub cbModSN_KeyDown(ByVal KeyCode As MSForms.ReturnInteger,
ByVal Shift As Integer)
If KeyCode < 13 Then Exit Sub
If Worksheets("Lists").Range("H:H").Find(cbModSN.Text ) Is Nothing Then
Worksheets("Lists").Range("H65535").End(xlUp).Offs et(1, 0).value =
cbModSN.Text
cbModSN.Text = ""
Else
' entry already exists. Perhaps add a message
End If
End Sub

Incidentally, I see no reason to use a combobox, a simple textbox
would work just as well.