View Single Post
  #14   Report Post  
r1024768 r1024768 is offline
Junior Member
 
Posts: 7
Default

Thanks! Ran that a couple of times and it seems to be consistently working fine.

So did the issue had something to do with the usage of ListBox.Value = x?
(I basically frankensteined the code together using google and a basic idea of programming languages in general, so I have no idea if there's anything I did that caused the issue)

Quote:
Originally Posted by GS[_2_] View Post
Change the following procedures as shown...

Private Sub CommandButton1_Click()
Dim vDataOut(1 To 3, 1 To 1)
vDataOut(1, 1) = ListBox1.List(ListBox1.ListIndex)
vDataOut(2, 1) = ListBox2.List(ListBox2.ListIndex)
vDataOut(3, 1) = ListBox3.List(ListBox3.ListIndex)
Range("B16").Resize(UBound(vDataOut), 1) = vDataOut
Unload Me
End Sub

Private Sub UserForm_Initialize()
Dim sz$
With Me.ListBox1
.List = Array("a", "b", "c"): .ListIndex = 1
sz = sz & .List(.ListIndex) '//value
End With 'ListBox1

With Me.ListBox2
.List = Array("a", "b", "c"): .ListIndex = 2
sz = sz & .List(.ListIndex) '//value
End With 'ListBox2

With Me.ListBox3
.List = Array("a", "b", "c"): .ListIndex = 0
sz = sz & .List(.ListIndex) '//value
End With 'ListBox3
MsgBox sz

Call Descript(ListBox1.List(ListBox1.ListIndex), "Box 1")
Call Descript(ListBox2.List(ListBox2.ListIndex), "Box 2")
End Sub

Private Sub Descript(Selection As String, Target As String)
Dim sMsg$, sz$, rngLookup As Range
If Selection = "" Or Target = "" Then Exit Sub

Select Case Target
Case "Box 1"
sz = Application.VLookup(Selection, Sheets("Data").Range("A2:B4"),
2, False)
If sz = "" Then sMsg = "error reading value for 1": GoTo ErrExit
Descript1.Caption = sz

Case "Box 2"
sz = Application.VLookup(Selection, Sheets("Data").Range("D2:E4"),
2, False)
If sz = "" Then sMsg = "error reading value for 2": GoTo ErrExit
Descript2.Caption = sz
End Select 'Case Target
GoTo NormalExit

ErrExit:
MsgBox sMsg

NormalExit:
Set rngLookup = Nothing
End Sub

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion