![]() |
Need help with Listboxes!
Alright, so here is my situation. I've tried to get this to work for a while now...and just can't seem to figure it out. Let's say you have columns A, B, C with data in them. Column D is a boolean value...true/false, 0/1, whatever. How would I populate a multi-column listbox with the data from A, B, and C depending on whether D is 0 or 1. So if it's 0, I want that row in the listbox, but if it's 1, I don't want it in the listbox. Of course I'd like this to work on all rows in the sheet. Could someone help me with the code for that? Thank you very much! -- Angelus ------------------------------------------------------------------------ Angelus's Profile: http://www.excelforum.com/member.php...o&userid=30721 View this thread: http://www.excelforum.com/showthread...hreadid=504144 |
Need help with Listboxes!
Private Sub UserForm_Initialize()
Dim rng As Range ListBox1.ColumnCount = 4 Set rng = Range(Cells(2, 1), Cells(2, 1).End(xlDown)) For Each cell In rng If cell.Offset(0, 3) = 0 Then ListBox1.AddItem cell.Value ListBox1.List(ListBox1.ListCount - 1, 1) = cell.Offset(0, 1).Value ListBox1.List(ListBox1.ListCount - 1, 2) = cell.Offset(0, 2).Value ListBox1.List(ListBox1.ListCount - 1, 3) = cell.Offset(0, 3).Value End If Next End Sub worked for me. -- Regards, Tom Ogilvy "Angelus" wrote in message ... Alright, so here is my situation. I've tried to get this to work for a while now...and just can't seem to figure it out. Let's say you have columns A, B, C with data in them. Column D is a boolean value...true/false, 0/1, whatever. How would I populate a multi-column listbox with the data from A, B, and C depending on whether D is 0 or 1. So if it's 0, I want that row in the listbox, but if it's 1, I don't want it in the listbox. Of course I'd like this to work on all rows in the sheet. Could someone help me with the code for that? Thank you very much! -- Angelus ------------------------------------------------------------------------ Angelus's Profile: http://www.excelforum.com/member.php...o&userid=30721 View this thread: http://www.excelforum.com/showthread...hreadid=504144 |
Need help with Listboxes!
Wow. Thanks a lot! Tom Ogilvy Wrote: Private Sub UserForm_Initialize() Dim rng As Range ListBox1.ColumnCount = 4 Set rng = Range(Cells(2, 1), Cells(2, 1).End(xlDown)) For Each cell In rng If cell.Offset(0, 3) = 0 Then ListBox1.AddItem cell.Value ListBox1.List(ListBox1.ListCount - 1, 1) = cell.Offset(0, 1).Value ListBox1.List(ListBox1.ListCount - 1, 2) = cell.Offset(0, 2).Value ListBox1.List(ListBox1.ListCount - 1, 3) = cell.Offset(0, 3).Value End If Next End Sub worked for me. -- Regards, Tom Ogilvy "Angelus" wrote in message ... Alright, so here is my situation. I've tried to get this to work for a while now...and just can't seem to figure it out. Let's say you have columns A, B, C with data in them. Column D is a boolean value...true/false, 0/1, whatever. How would I populate a multi-column listbox with the data from A, B, and C depending on whether D is 0 or 1. So if it's 0, I want that row in the listbox, but if it's 1, I don't want it in the listbox. Of course I'd like this to work on all rows in the sheet. Could someone help me with the code for that? Thank you very much! -- Angelus ------------------------------------------------------------------------ Angelus's Profile: http://www.excelforum.com/member.php...o&userid=30721 View this thread: http://www.excelforum.com/showthread...hreadid=504144 -- Angelus ------------------------------------------------------------------------ Angelus's Profile: http://www.excelforum.com/member.php...o&userid=30721 View this thread: http://www.excelforum.com/showthread...hreadid=504144 |
Need help with Listboxes!
Okay, I need a little more help here. Once an entry in the listbox is selected and a command button is pushed, how do I get the value of the second column? It would be something like: newVariable = ListBox1.List(X, 1) What do I put where the X is to specify the entry that has been selected? Thanks. -- Angelus ------------------------------------------------------------------------ Angelus's Profile: http://www.excelforum.com/member.php...o&userid=30721 View this thread: http://www.excelforum.com/showthread...hreadid=504144 |
Need help with Listboxes!
Nevermind, I figured it out. -- Angelus ------------------------------------------------------------------------ Angelus's Profile: http://www.excelforum.com/member.php...o&userid=30721 View this thread: http://www.excelforum.com/showthread...hreadid=504144 |
All times are GMT +1. The time now is 06:16 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com