-
Apr 5th, 2018, 06:42 AM
#1
Thread Starter
New Member
Adding 2 columns to ComboBox in Form from table
Hey guys. Firstly I am beginner, so dont kill me :D
I have a problem. I have to make 2 column ComboBox in Form. Added data must be from table in sheet, BUT dont know the number of lines, so firstly I have to do that (as u can see in code- that is X)
Table looks like this
Then I tried 2 ways how to add that 2 columns with X lines to ComboBox in Form. This is code:
Code:
Private Sub UserForm_Initialize()
Dim x As Byte
Dim riadok As Byte
x = 1
While Range("ODBERATELE!B" & x) <> ""
x = x + 1
Wend
MsgBox x
'''''''''''''''''1.WAY - Error 381 :(
For riadok = 2 To x
With UserForm1.ComboBox1
.List = Sheets("ODBERATELE").Range("A" & riadok & ":" & "B" & riadok).Value
.ColumnCount = 2
.ColumnWidths = "50;50"
End With
Next riadok
'''''''''''''''''''''''''''''''2.way I have tried has problem with X
Dim adresy(1 To x, 1 To x) As String
Me.ComboBox1.ColumnCount = 2
For riadok = 2 To x
adresy(riadok, 1) = Sheets("ODBERATELE").Range("A" & riadok)
adresy(riadok, 2) = Sheets("ODBERATELE").Range("B" & riadok)
Next riadok
Me.ComboBox1.List = adresy
End Sub
Any idea what Im doing wrong, please? :)
-
Apr 6th, 2018, 02:31 PM
#2
Re: Adding 2 columns to ComboBox in Form from table
No, but I believe you may be working in VBA, not VB6 (lots of folks get confused on this one).
I'll notify Moderators...if they deem it be moved, they will...otherwise, someone with more intelligence than I would have to assist you.
Sammi
-
Apr 6th, 2018, 07:39 PM
#3
Re: Adding 2 columns to ComboBox in Form from table
It does look like VBA, so I've moved it to Office Development. If that was wrong, send me a PM.
My usual boring signature: Nothing
-
Apr 6th, 2018, 11:35 PM
#4
Re: Adding 2 columns to ComboBox in Form from table
this has been answered in the other thread
this one does have a better title though
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|