Re: How do I get a list from an excel sheet into a userform/listbox?
- From: Örjan Kihlbaum <Kihlbaum@xxxxxxxxx>
- Date: Wed, 31 Oct 2007 14:39:41 -0000
On Oct 31, 3:22 pm, gwoo...@xxxxxxxxx wrote:
On Oct 31, 9:02 am, Örjan Kihlbaum <Kihlb...@xxxxxxxxx> wrote:
Hello all,
I am very new to the VBA programming language. I have managed to solve
most of my problems by looking for answers here, on the Internet and
in a nice little book called "Excel 2003 VBA".
Background:
I am planning to have a excel *** that can display information based
on a list located in another *** (a database of sorts). So, the
"database ***" contains names,numbers and values and I plan to have
a "display ***" that will display values and calculations for one
member of the database/list at a time.
VBA involvment:
I want to be able to press a button to open up a simple userform with
a listbox.
In the listbox I want to list the members of the database.
When I click on any of the members I want the userform to close and
that the values for that perticular member to be displayed in my
"display ***".
Problem:
Well, the excel part is easy enough but I really don't know where to
start with the VBA.
I have created a userfrom and I have added a listbox.
Now how do I get the listbox to display the "members" from the
database ***?
All the rest I'll worry about later.. :)
I haven't found any article yet to help me so maybe anyone here knows
where I should start to look for info?
Or can you give a hint so I know where to start?
Wouldnt it be easier to just add a find button, and a textbox to
input the name they are looking for ?
Private Sub CommandButton1_Click()
Dim rng As Range
Dim ws As Work***
Dim SearchTxt As String
Dim Row As Integer
Dim firstAddress As String
Set ws = Worksheets("sheet1")
SearchTxt = TextBox1.Text ' This is textbox they are
putting the name into
If TextBox1.Text= "" Then
GoTo ErrorMessage
End If
Set rng = ws.Cells.Find(What:=SearchTxt, After:=ws.Range("A1"), _
LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
If Not r Is Nothing Then
firstAddress = r.Address
Do
Set rng = Cells.FindNext(rng)
Listbox.AddItem (rng)
Loop While Not rng Is Nothing And rng.Address <> firstAddress
Else
' What you want it to do if thats false
End if
ErrorMessage:
MsgBox "Please Type a Name", vbInformation, " No Names found"
End Sub- Hide quoted text -
- Show quoted text -
Nope, sorry. It needs to be supersimple. Having to type in the names
wont do unfortunally.
Thanks though!
.
- References:
- How do I get a list from an excel *** into a userform/listbox?
- From: Örjan Kihlbaum
- Re: How do I get a list from an excel *** into a userform/listbox?
- From: gwoodby
- How do I get a list from an excel *** into a userform/listbox?
- Prev by Date: Re: Missing Data
- Next by Date: Re: How do I get a list from an excel *** into a userform/listbox?
- Previous by thread: Re: How do I get a list from an excel *** into a userform/listbox?
- Next by thread: Re: How do I get a list from an excel *** into a userform/listbox?
- Index(es):