+ Reply to Thread
Results 1 to 5 of 5

listbox display vertically and not horizontally

  1. #1
    Registered User
    Join Date
    06-24-2013
    Location
    KC, MO
    MS-Off Ver
    excel 2013
    Posts
    11

    listbox display vertically and not horizontally

    I have a listbox (listbox1) that is populating based on a combobox (cboSRegions) selection on a userform (frmOutreach). My data range is from A3:M with row 3 being column headings. cboSREgions search criteria is located in column B. My problem is I can get the listbox to display all the corresponding fields (13 columns of data) but it only displays it vertically in one column and not 13 columns of data horizontally. Here is my code that I am using:
    Please Login or Register  to view this content.
    Can you tell me what I am doing wrong? I also tried application.transpose but that didn't work. What I want is to display all 13 columns in one row based on combobox criteria. In other words, I want to display the entire row of data based on the criteria selected in the combobox. Also, if this is done, will the listbox be able to display all 13 columns using additem? If not, can you suggest a better way? Thank you in advance for any and all assistance.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: listbox display vertically and not horizontally

    AddItem adds a row each time you use it.

    So this is adding 13 rows to the lisbox each time.
    Please Login or Register  to view this content.
    Normally you would have one AddItem to add the row and then code using List to fill the row in.

    Unfortunately since you have 13 columns you can't actually use AddItem, it's limited to 9 (or is it 10?) columns.

    To populate a listbox with that no of columns you'll either need to use a range or an array.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    06-24-2013
    Location
    KC, MO
    MS-Off Ver
    excel 2013
    Posts
    11

    Re: listbox display vertically and not horizontally

    Thanks for you quick response Norie. I am very new to VBA. Is it possible for you to provide a snippet of code that I can modify regarding arrays or the range process that you are referencing. I am not familiar with that approach. Do you have any additional guidance to offer?

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: listbox display vertically and not horizontally

    This is a very simple example but hopefully will show the basics.

    It's for a range from A:M and fills the array if the value in A is 'A'.
    Please Login or Register  to view this content.
    Note, arrays are zero-indexed, so the first dimension of arrData is from 0 To 12 which is 13 items.

    Also, when using Redim Preserve only the last dimension of an array can be changed.

    That means we build the array the 'wrong way round' and then use Application.Transpose when populating the listbox.

  5. #5
    Registered User
    Join Date
    06-24-2013
    Location
    KC, MO
    MS-Off Ver
    excel 2013
    Posts
    11

    Re: listbox display vertically and not horizontally

    Thank you Norie for your guidance and code snippet. It worked perfectly with just a minor modification. Thanks again ever soooo much.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Sumproduct vertically and horizontally
    By jimstrongy in forum Excel General
    Replies: 2
    Last Post: 03-21-2012, 04:37 PM
  2. Searching a table vertically and Horizontally
    By smokeydawson555 in forum Excel General
    Replies: 3
    Last Post: 06-29-2009, 11:55 PM
  3. UDF to Display Results Vertically Instead of One Cell Horizontally
    By snake10 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-13-2008, 12:18 PM
  4. Move cells vertically to horizontally
    By Abe in forum Excel General
    Replies: 1
    Last Post: 03-22-2005, 11:07 PM
  5. Replies: 2
    Last Post: 02-14-2005, 01:48 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1