Form Default Value

  • Thread starter Thread starter bw
  • Start date Start date
B

bw

The following is code for a UserForm. The Value of A1 in Sheet2 contains
the value that I want to use as the default value for this form. The value
of A1 is dynamic, and is the same as one of the values in the
CombinedBankNames List.
How do I do this please.

Thanks,
Bernie

Private Sub CombinedBankNames_Change()
boxvalue = CombinedBankNames.Value
Call MoveBankData
End Sub

Private Sub UserForm_Initialize()
Dim MyArray As Variant
'Where mylist is the named range
MyArray = Range("CombinedData")
CombinedBankNames.List = MyArray
End Sub
 
This seemed to work ok:

Option Explicit
Dim blkProc As Boolean
Private Sub UserForm_Initialize()
Dim res As Variant
Dim MyArray As Variant
'Where mylist is the named range
MyArray = Range("CombinedData")
CombinedBankNames.List = MyArray
res = Application.Match( _
ThisWorkbook.Worksheets("sheet2").Range("a1").Value, _
Me.CombinedBankNames.List, 0)
If IsError(res) Then
'no match, design error??
'do nothing
Else
blkProc = True
Me.CombinedBankNames.ListIndex = res - 1
blkProc = False
End If
End Sub

Private Sub CombinedBankNames_Change()
If blkProc = True Then Exit Sub
MsgBox "hi"
' boxvalue = CombinedBankNames.Value
' Call MoveBankData
End Sub

The blkProc stuff stops the _change procedure from doing anything if we're just
loading the combobox (it was a combobox, right?).
 
Back
Top