• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 258
  • Last Modified:

Select from two List boxes and send to workbook

Hi,

I have attached a screenshot of a listbox i have created. I have populated the data, now i need code that allows the user to click on the book and click on then a book home and press "Enter Map"

On pressing "Enter Map" i want the book and book home to be sent to a workbook called ("Match.xl") sheet is called "Mapping Table" and the range it needs to be sent is K2:L2 to how many rows needed

So i need the user to press ctrl and select the book and book home and then the data to be sent

I am open to sending this data differently if this is not the most efficient way of sending the data

Thanks
Seamus
Doc4.doc
0
Seamus2626
Asked:
Seamus2626
  • 8
  • 7
1 Solution
 
Frank WhiteCommented:
Seems you created a second question. Might want to call for a moderator to delete one of them.

Important detail: What language/software was this listbox window you created made in? Is it a VBA window that appears upon running a macro in Excel or Word, or is it a completely independent/separate C#/C++/VB.NET/.NET/etc. program that happens to contain that window? Is it run from the same workbook you want to send the data to (i.e. just send data from one worksheet to another?), or is it two different Excel workbooks (files)?
0
 
Seamus2626Author Commented:
Ive requested the delete

Its excel VBA. Its running through Excel only.

It picks data from a temporary sheet and fills the first list out

bolix
shite (test data!)

The second part

Paris
Hong kong etc

is held on a static table in the same WB the code is running from (match.xls)

So what im trying to do is union the test data with the static list and send them to a sheet in Match.xls

The whole point of the exercise is to fill a mapping table before some code is run.

Hope thats clearer!

Thanks
Seamus
0
 
NorieVBA ExpertCommented:
Seamus

Is this a userform?

If it is what are the names of the listboxes?

What do you mean exactly by a 'mapping' table?

Do you want to transfer the data from one listbox to one column, with the data from the other listbox in the column to the right.

Something like this.

Column A                        Column B
      
ListBox1Item1      Listbox2Item1
ListBox1Item2      Listbox2Item2
ListBox1Item3      Listbox2Item3

etc
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
Seamus2626Author Commented:
Hi imnorie,

It is a userform and there is ListBox1+Listbox2

The mapping table is used in another part of the code and basically identifys trade books to areas, so "bolix" to "Paris"

Yes, exactly. I would like to drop them into two columns exactly as you have above

Thanks
Seamus
0
 
NorieVBA ExpertCommented:
Try this, it assumes both listboxes have the same no of rows.
Dim I As Long

For I = 0 To Listbox1.Count-1
       Worksheets("Mapping Table").Range("K2").offset(I).Value = Listbox1.List(I)
       Worksheets("Mapping Table").Range("L2").Offset(I).Value = Listbox2.List(I)
Next I

Open in new window

0
 
NorieVBA ExpertCommented:
Seamus

Here's something that doesn't use a loop.
Dim arrList

arrList = Listbox1.List

Range("K2").Resize(ubound(arrlist)).Value = arrList

arrList = Listbox2.List

Range("L2").Resize(ubound(arrlist)).Value = arrList

Open in new window

0
 
Seamus2626Author Commented:
Hey Imnorie,

Ive just been thinking, i store the first list in the mapping table already In Column A, if the user selected the top list and then the appropriate area and pressed the button, if the selected data in the second list was send to

Mapping Table, Range("B1").Xlenddown.offset(1,0)

then it would line up with the area and be exactly what i needed

I know the syntax for the above is completely wrong!

But basically, once List2 was selected, they hit the button and it was sent to the next empty cell in Column B, it would line up!

Thanks
Seamus
0
 
NorieVBA ExpertCommented:
Seamus

So you don't need the listboxes?

By the way, don't use xlDown to try and find the next empty row - it will work sometimes but there's also a chance it could cause problems.

Use xlDown instead:
' find next empty cell in column A
Set NextCell = Worksheets("Mapping Table").Range("A" & Rows.Count).End(xlUp).Offset(1)

Open in new window

0
 
Seamus2626Author Commented:
Ya i need the Listboxes, i dont want the users to be able to get at the mapping table or the lists.

Set NextCell = Worksheets("Mapping Table").Range("A" & Rows.Count).End(xlUp).Offset(1)

I get a subscript out of range error here because the tab mapping table is in a wb called match.xls and i am running this out of spreadsheet called aspa.xls

Can you amend the above?

Thanks
Seamus
0
 
NorieVBA ExpertCommented:
Seamus

Just add a workbook reference in front of Worksheets.
Workbooks("aspa.xls").Worksheets...

Open in new window

0
 
Seamus2626Author Commented:
Thanks again Inmorie, on the command button i have this code

Set NextCell = Workbooks("Match.xls").Worksheets("Mapping Table").Range("B" & Rows.Count).End(xlUp).Offset(1)

this selects the correct cell in the mapping table but does not send the item from Listbox2 to that cell.
Am i missing a line?

Thanks
Seamus
0
 
NorieVBA ExpertCommented:
In the rest of the code for the button click to you use NextRow?
0
 
Seamus2626Author Commented:
Ok, so when the list boxes have been filled out (like on the word doc) the user presses the button

"Enter Map"

For that button i have your code


Private Sub SendingData_Click()



Set NextCell = Workbooks("Match.xls").Worksheets("Mapping Table").Range("B" & Rows.Count).End(xlUp).Offset(1)

End Sub


This correctly selects the cell in the sheet "Mapping Table"

What i want is for it also to send the piece of data in the second list box that the user has selected e.g. New York

Thanks
Seamus
0
 
NorieVBA ExpertCommented:
Seamus

I'm totally confused, you now only want data from Listbox2 to be written to the worksheet.

The code for that would be this.
Private Sub SendingData_Click()
Dim NextCell As Range
Dim arrList

     Set NextCell = Workbooks("Match.xls").Worksheets("Mapping Table").Range("B" & Rows.Count).End(xlUp).Offset(1)

     arrList = Listbox2.List

     NextCell.Resize(UBound(arrlist)).Value = arrList

End Sub

Open in new window

0
 
Seamus2626Author Commented:
Thank inmorie,

Your code is working and sending the data.


I have other issues with my userform which il post tomorrow

Thanks fo your patience today!

Seamus
0
 
NorieVBA ExpertCommented:
Seamus

Why not attach a workbook with the userform instead of just pictures?

Might help clarify things.

Obviously remove any sensitive data.:)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

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.

  • 8
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now