View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
BrianB BrianB is offline
external usenet poster
 
Posts: 1
Default Variable scope question w/combo-box

I have amended your code and copied below. You can copy/paste into the
appropriate place.

1. There was a spelling error in "UserFrom_Initialize()" which I have
corrected. You would get no error message because the name is valid for
a subroutine.

2. There is no point here bothering with the scope of variable names
because your form will retain the combo selection value until it is
unloaded, when it is lost. You therefore need to save it somewhere
before you unload the form. I have used Cell A1 here.

'====================
' WORKSHEET CODE
'====================
Private Sub Worksheet_Change(ByVal RangeChanged As Range)
If RangeChanged.Column = 2 And Curr_User = "" Then
'Load frmRequestor ' ** do not really need
frmRequestor.Show
' Curr_User = frmRequestor.cbxRequestor.Value ' not needed **
ActiveSheet.Range("A1").Value = _
frmRequestor.cbxRequestor.Value '**
Unload frmRequestor
End If
End Sub
'-- END OF WORKSHEET CODE ----------------

'==============
' FORM CODE
'==============
Private Sub Done_Click()
frmRequestor.Hide
End Sub


Private Sub UserForm_Initialize() '** originally misspelled
cbxRequestor.AddItem "Choice 1"
cbxRequestor.AddItem "Choice 2"
cbxRequestor.AddItem "Choice 3"
cbxRequestor.AddItem "Choice 4"
cbxRequestor.AddItem "Choice 5"
cbxRequestor.ListIndex = 0 ' added ***
' MsgBox cbxRequestor '*** delete
End Sub
'-- END OF FORM CODE ----------------------


---
Message posted from http://www.ExcelForum.com/