Results 1 to 10 of 10

Thread: [RESOLVED] List box

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2020
    Posts
    8

    Resolved [RESOLVED] List box

    Hello, i have problem , when ever i try to add info from cells to list box it also adds empty spaces, how could i change this?
    Here is my code


    Code:
    Private Sub CommandButton1_Click()
        ListBox1.Clear
    
    
        If TypeOf Selection Is Range Then
            For i = 1 To Selection.Rows.Count
                For j = 1 To Selection.Columns.Count
    
    
                    ListBox1.AddItem (Selection.Cells(i, j))
    
    
                Next
            Next
        End If
    
    End Sub
    Last edited by dday9; Dec 11th, 2020 at 10:52 AM. Reason: Added Code Tags

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: List box

    Are you sure that this is VB.NET? Looks more like VB6 or maybe VBA.

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2020
    Posts
    8

    Re: List box

    Im not sure i know the difference. what forum would you suggest me?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: List box

    I would suggest that you work out what language you're actually using and then post in the forum dedicated to that language.

  5. #5
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: List box

    What software application are you using to develop the code?
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  6. #6

    Thread Starter
    New Member
    Join Date
    Nov 2020
    Posts
    8

    Re: List box

    Microsoft excel

  7. #7
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: List box

    Moved to office development which is for VBA questions.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: List box

    try like
    Code:
                   if not isempty(selection.celss(i, j)) then ListBox1.AddItem (Selection.Cells(i, j))
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  9. #9

    Thread Starter
    New Member
    Join Date
    Nov 2020
    Posts
    8

    Re: List box

    Okey, tnx, but how could i integrete in my code?
    Do i make another ''if'' or i add it with ''and'' to the first one?

  10. #10
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: List box

    just swap it in place of the existing line to additems
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width