![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Location: Hengelo
Posts: 79
|
Hello,
In column A I have years. In column B I have names. Years Names 1990 James 1997 Rick 1982 Dan … … I want to load the years and the names into a listbox on a userform. The listbox must have two columns and columnheads (for Years and Names). How do I program that in VB?!
__________________
Best regards, Martin J.A. Maatman Oonk |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Apr 2002
Location: Vancouver BC , Canada
Posts: 6,259
|
Is this what you want ?
Code:
Public Sub AddItemsToList()
Tb = Chr(9)
ListBox1.AddItem "Years" & Tb & "Names", 0
ListBox1.AddItem "1990" & Tb & "James", 1
ListBox1.AddItem "1997" & Tb & "Rick", 2
End Sub
|
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Feb 2002
Location: Hengelo
Posts: 79
|
Hello,
The list of years and names can vary so I need a flexibel code! E.g. "currentregion".
__________________
Best regards, Martin J.A. Maatman Oonk |
|
|
|
|
|
#4 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
|
Quote:
Either Set up the properties in Design mode eg set the Listbox properties for; ColumnCount RowSource ColumnHeads OR via code Private Sub UserForm_Initialize() With ListBox1 .ColumnCount = 2 .RowSource = "A2:B12" .ColumnHeads = True End With End Sub ' ' ' If your row source is dynamic then try something like; ' ' ' Dim Rg As Range Set Rg = Range(Range("A2"), Range("B2").End(xlDown)) With ListBox1 .ColumnCount = 2 .RowSource = Rg.Address .ColumnHeads = True End With |
|
|
|
|
|
|
#5 |
|
MrExcel MVP
Join Date: Apr 2002
Location: Vancouver BC , Canada
Posts: 6,259
|
When and from where are the names and years coming from ?
Are they being loaded at the same time as the form ? or afterwards ? Is the data coming from a predetermined list .. ie excel spreadsheet or enter by user after the form is loaded ?
__________________
<MARQUEE>...........Never be afraid to try something new. Remember, amateurs built the ark, professionals built the Titanic...............The easiest thing to find is fault, don't be easy !.. --Anonymous--...</marquee> |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|