?
Solved

Placing data in listbox excel macro

Posted on 2005-04-24
3
Medium Priority
?
958 Views
Last Modified: 2008-01-09
I'm trying to do the following in excel macro:

Form a has a list box and a control button
Form b has a list box and a control button

I want to call a subroutine (the same sunroutine) that will populate the same data into the list box when the control button is clicked.

For example
When controll button on form a is clicked. It calls sub select_customers that puts a list of customers in the list box.
When controll button on form b is clicked. It also calls sub select_customers thta puts a list of customers in the list box.
 The problem I am having is when the sub is called I loose focus of the form that called it.

Thanks
0
Comment
Question by:whiwex
3 Comments
 
LVL 10

Expert Comment

by:Eduard Ghergu
ID: 13856258
I have a question: How do you call the forms? You have buttons in a sheet or a menu?
0
 

Author Comment

by:whiwex
ID: 13857254
Yes I call the form via a button on the previous form.
When i get into the sub I don't know how to send the list to the list box on the form that called the sub
0
 
LVL 6

Accepted Solution

by:
parkerig earned 2000 total points
ID: 13863127
Hi,
One way of doing this is to have the list boxes refer to a range on a worksheet.
Just have form1 and form2 both pointing at the same range

In this example I had the ShowModal property set to false

' Code for UserForm1
Option Explicit

Private Sub CommandButton1_Click()
    DoEvents
    'UserForm1.Hide
    UserForm2.Show 0
End Sub


Sub UserForm_Initialize()
    UserForm1.ListBox1.RowSource = "A1:A12"
    'UserForm1.ListBox1.ControlSource = "A1"
    'UserForm1.ListBox1.BoundColumn = 0
End Sub

' Code for UserForm2
Option Explicit
Private Sub CommandButton1_Click()
    DoEvents
    'UserForm2.Hide
    UserForm1.Show 0
End Sub



Sub UserForm_Initialize()
    UserForm2.ListBox1.RowSource = "A1:A12" ' or use a RANGENAME
    'UserForm2.ListBox1.ControlSource = "c6"
    'UserForm2.ListBox1.BoundColumn = 0
End Sub


0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question