Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 213
Default Listbox populating progmatically

I have this list (for a listbox), condensed for this query..
'=====================
Private Sub UserForm_Initialize()
Me.ListBox1.AddItem ("1")
Me.ListBox1.AddItem ("2")
Me.ListBox1.AddItem ("3")
Me.ListBox1.AddItem ("4")
Me.ListBox1.AddItem ("5")
End Sub
'================

How do I read from that list and create code to mimick the following.
'==============
With ListBox1
If .Value = "1" Then
If .Value = "2" Then
If .Value = "3" Then
If .Value = "4" Then
If .Value = "5" Then
End If
End If
End If
End If
End If
'some code goes here
End With
'===============

I would like to prevent constant editing of the macro to accomidate new
entries.

--
Regards

Rick
XP Pro
Office 2007

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Listbox populating progmatically

Look at ListIndex in VBA help, it should give you what you want

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Rick S." wrote in message
...
I have this list (for a listbox), condensed for this query..
'=====================
Private Sub UserForm_Initialize()
Me.ListBox1.AddItem ("1")
Me.ListBox1.AddItem ("2")
Me.ListBox1.AddItem ("3")
Me.ListBox1.AddItem ("4")
Me.ListBox1.AddItem ("5")
End Sub
'================

How do I read from that list and create code to mimick the following.
'==============
With ListBox1
If .Value = "1" Then
If .Value = "2" Then
If .Value = "3" Then
If .Value = "4" Then
If .Value = "5" Then
End If
End If
End If
End If
End If
'some code goes here
End With
'===============

I would like to prevent constant editing of the macro to accomidate new
entries.

--
Regards

Rick
XP Pro
Office 2007



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 213
Default Listbox populating progmatically

Thank you Bob, I can now Add and/or Remove Items from my Listbox!
What I am failing to see is how to append, add or remove the Items to my
hard coded list. I have never tried to write code into a macro before and I
am not finding information "How to", I may not know what to search for?
Below is my list that I need to append, add or remove lines from.

'==========
Private Sub UserForm_Initialize()
Me.ListBox1.AddItem ("1")
Me.ListBox1.AddItem ("2")
Me.ListBox1.AddItem ("3")
Me.ListBox1.AddItem ("4")
Me.ListBox1.AddItem ("5")
End Sub
'==========

I am not looking just for "The Code"; direction like you have provided is
allways welcome!

--
Regards

Rick
XP Pro
Office 2007



"Bob Phillips" wrote:

Look at ListIndex in VBA help, it should give you what you want

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Rick S." wrote in message
...
I have this list (for a listbox), condensed for this query..
'=====================
Private Sub UserForm_Initialize()
Me.ListBox1.AddItem ("1")
Me.ListBox1.AddItem ("2")
Me.ListBox1.AddItem ("3")
Me.ListBox1.AddItem ("4")
Me.ListBox1.AddItem ("5")
End Sub
'================

How do I read from that list and create code to mimick the following.
'==============
With ListBox1
If .Value = "1" Then
If .Value = "2" Then
If .Value = "3" Then
If .Value = "4" Then
If .Value = "5" Then
End If
End If
End If
End If
End If
'some code goes here
End With
'===============

I would like to prevent constant editing of the macro to accomidate new
entries.

--
Regards

Rick
XP Pro
Office 2007




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Listbox populating progmatically

Rick,

You have clearly demonstrated that you know how to add the item.

If you looked at ListIndex in help you should have gathered that Listindex
points at the item in the list that is selected. pair this with the
RemoveItem method, and you can delete the selected item

With Me.ListBox1
.RemoveItem (.ListIndex)
End With


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Rick S." wrote in message
...
Thank you Bob, I can now Add and/or Remove Items from my Listbox!
What I am failing to see is how to append, add or remove the Items to my
hard coded list. I have never tried to write code into a macro before and
I
am not finding information "How to", I may not know what to search for?
Below is my list that I need to append, add or remove lines from.

'==========
Private Sub UserForm_Initialize()
Me.ListBox1.AddItem ("1")
Me.ListBox1.AddItem ("2")
Me.ListBox1.AddItem ("3")
Me.ListBox1.AddItem ("4")
Me.ListBox1.AddItem ("5")
End Sub
'==========

I am not looking just for "The Code"; direction like you have provided is
allways welcome!

--
Regards

Rick
XP Pro
Office 2007



"Bob Phillips" wrote:

Look at ListIndex in VBA help, it should give you what you want

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)



"Rick S." wrote in message
...
I have this list (for a listbox), condensed for this query..
'=====================
Private Sub UserForm_Initialize()
Me.ListBox1.AddItem ("1")
Me.ListBox1.AddItem ("2")
Me.ListBox1.AddItem ("3")
Me.ListBox1.AddItem ("4")
Me.ListBox1.AddItem ("5")
End Sub
'================

How do I read from that list and create code to mimick the following.
'==============
With ListBox1
If .Value = "1" Then
If .Value = "2" Then
If .Value = "3" Then
If .Value = "4" Then
If .Value = "5" Then
End If
End If
End If
End If
End If
'some code goes here
End With
'===============

I would like to prevent constant editing of the macro to accomidate new
entries.

--
Regards

Rick
XP Pro
Office 2007






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 213
Default Listbox populating progmatically

I will gather that due to my novice programming I did not explain my self
propperly. I do now understand how to add or remove an item from the listbox
per your initial and helpfull advice. What I am attempting now is to add or
append to a typed list within the macro and not within the listbox.

By playing with AddItem and RemoveItem I noticed when I refresh the listbox
my original list reapears and any added items do not or removed items have
returned due to Userform_Intialize commands.
Me.ListBox1.AddItem ("1")
Me.ListBox1.AddItem ("2")
etc. etc.

--
Regards

Rick
XP Pro
Office 2007



"Bob Phillips" wrote:

Rick,

You have clearly demonstrated that you know how to add the item.

If you looked at ListIndex in help you should have gathered that Listindex
points at the item in the list that is selected. pair this with the
RemoveItem method, and you can delete the selected item

With Me.ListBox1
.RemoveItem (.ListIndex)
End With


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Rick S." wrote in message
...
Thank you Bob, I can now Add and/or Remove Items from my Listbox!
What I am failing to see is how to append, add or remove the Items to my
hard coded list. I have never tried to write code into a macro before and
I
am not finding information "How to", I may not know what to search for?
Below is my list that I need to append, add or remove lines from.

'==========
Private Sub UserForm_Initialize()
Me.ListBox1.AddItem ("1")
Me.ListBox1.AddItem ("2")
Me.ListBox1.AddItem ("3")
Me.ListBox1.AddItem ("4")
Me.ListBox1.AddItem ("5")
End Sub
'==========

I am not looking just for "The Code"; direction like you have provided is
allways welcome!

--
Regards

Rick
XP Pro
Office 2007



"Bob Phillips" wrote:

Look at ListIndex in VBA help, it should give you what you want

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)



"Rick S." wrote in message
...
I have this list (for a listbox), condensed for this query..
'=====================
Private Sub UserForm_Initialize()
Me.ListBox1.AddItem ("1")
Me.ListBox1.AddItem ("2")
Me.ListBox1.AddItem ("3")
Me.ListBox1.AddItem ("4")
Me.ListBox1.AddItem ("5")
End Sub
'================

How do I read from that list and create code to mimick the following.
'==============
With ListBox1
If .Value = "1" Then
If .Value = "2" Then
If .Value = "3" Then
If .Value = "4" Then
If .Value = "5" Then
End If
End If
End If
End If
End If
'some code goes here
End With
'===============

I would like to prevent constant editing of the macro to accomidate new
entries.

--
Regards

Rick
XP Pro
Office 2007









  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Listbox populating progmatically

By refresh, do you mean that when you restart the form? This would be
because you reload it on re-showing the form.

Instead of unloading the form, just hid it, the Initialize event doesn't
fire then.

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Rick S." wrote in message
...
I will gather that due to my novice programming I did not explain my self
propperly. I do now understand how to add or remove an item from the
listbox
per your initial and helpfull advice. What I am attempting now is to add
or
append to a typed list within the macro and not within the listbox.

By playing with AddItem and RemoveItem I noticed when I refresh the
listbox
my original list reapears and any added items do not or removed items have
returned due to Userform_Intialize commands.
Me.ListBox1.AddItem ("1")
Me.ListBox1.AddItem ("2")
etc. etc.

--
Regards

Rick
XP Pro
Office 2007



"Bob Phillips" wrote:

Rick,

You have clearly demonstrated that you know how to add the item.

If you looked at ListIndex in help you should have gathered that
Listindex
points at the item in the list that is selected. pair this with the
RemoveItem method, and you can delete the selected item

With Me.ListBox1
.RemoveItem (.ListIndex)
End With


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)



"Rick S." wrote in message
...
Thank you Bob, I can now Add and/or Remove Items from my Listbox!
What I am failing to see is how to append, add or remove the Items to
my
hard coded list. I have never tried to write code into a macro before
and
I
am not finding information "How to", I may not know what to search for?
Below is my list that I need to append, add or remove lines from.

'==========
Private Sub UserForm_Initialize()
Me.ListBox1.AddItem ("1")
Me.ListBox1.AddItem ("2")
Me.ListBox1.AddItem ("3")
Me.ListBox1.AddItem ("4")
Me.ListBox1.AddItem ("5")
End Sub
'==========

I am not looking just for "The Code"; direction like you have provided
is
allways welcome!

--
Regards

Rick
XP Pro
Office 2007



"Bob Phillips" wrote:

Look at ListIndex in VBA help, it should give you what you want

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)



"Rick S." wrote in message
...
I have this list (for a listbox), condensed for this query..
'=====================
Private Sub UserForm_Initialize()
Me.ListBox1.AddItem ("1")
Me.ListBox1.AddItem ("2")
Me.ListBox1.AddItem ("3")
Me.ListBox1.AddItem ("4")
Me.ListBox1.AddItem ("5")
End Sub
'================

How do I read from that list and create code to mimick the
following.
'==============
With ListBox1
If .Value = "1" Then
If .Value = "2" Then
If .Value = "3" Then
If .Value = "4" Then
If .Value = "5" Then
End If
End If
End If
End If
End If
'some code goes here
End With
'===============

I would like to prevent constant editing of the macro to accomidate
new
entries.

--
Regards

Rick
XP Pro
Office 2007









  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default Listbox populating progmatically

... I need to append, add or remove lines from.

Not sure it this is what you need.

Private Sub UserForm_Initialize()
'// Add
Me.ListBox1.List = Array(1, 2, 3, 4, 5)
'// Delete
Me.ListBox1.RemoveItem (0) 'Remove 1st item
'//Append
Me.ListBox1.AddItem 11
End Sub

--
Dana DeLoui

"Rick S." wrote in message
...
Thank you Bob, I can now Add and/or Remove Items from my Listbox!
What I am failing to see is how to append, add or remove the Items to my
hard coded list. I have never tried to write code into a macro before and
I
am not finding information "How to", I may not know what to search for?
Below is my list that I need to append, add or remove lines from.

'==========
Private Sub UserForm_Initialize()
Me.ListBox1.AddItem ("1")
Me.ListBox1.AddItem ("2")
Me.ListBox1.AddItem ("3")
Me.ListBox1.AddItem ("4")
Me.ListBox1.AddItem ("5")
End Sub
'==========

I am not looking just for "The Code"; direction like you have provided is
allways welcome!

--
Regards

Rick
XP Pro
Office 2007



"Bob Phillips" wrote:

Look at ListIndex in VBA help, it should give you what you want

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)



"Rick S." wrote in message
...
I have this list (for a listbox), condensed for this query..
'=====================
Private Sub UserForm_Initialize()
Me.ListBox1.AddItem ("1")
Me.ListBox1.AddItem ("2")
Me.ListBox1.AddItem ("3")
Me.ListBox1.AddItem ("4")
Me.ListBox1.AddItem ("5")
End Sub
'================

How do I read from that list and create code to mimick the following.
'==============
With ListBox1
If .Value = "1" Then
If .Value = "2" Then
If .Value = "3" Then
If .Value = "4" Then
If .Value = "5" Then
End If
End If
End If
End If
End If
'some code goes here
End With
'===============

I would like to prevent constant editing of the macro to accomidate new
entries.

--
Regards

Rick
XP Pro
Office 2007




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Populating listbox Mick[_2_] Excel Discussion (Misc queries) 1 May 14th 08 10:48 PM
populating a listbox enyaw Excel Programming 3 November 28th 06 06:48 AM
Populating listbox Andy Brown Excel Programming 3 August 16th 04 05:40 PM
Populating a ListBox ToddG Excel Programming 1 June 24th 04 03:18 AM
Populating a userform 3 col listbox Martin[_13_] Excel Programming 0 April 19th 04 09:49 PM


All times are GMT +1. The time now is 08:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"