Results 1 to 3 of 3

Thread: how to display content in excel sheet using listbox rowsource vba

  1. #1

    how to display content in excel sheet using listbox rowsource vba

    Register for a FREE account, and/
    or Log in to avoid these ads!

    I get the data in listbox from sheet2 of the excel file in my form. After i fill in all the data required, i want to display all of the data to sheet1 of the excel file including the data in the listbox rowsource. I am able to get the data to put into the listbox, but i don't know how to display it in sheet1. Is there anyone know how to do it?
    i had uploaded the sample file in the thread.
    Attached Files Attached Files

  2. #2
    Hi tkfei...

    for getting a value of an existing item of a Listbox and then write this value to a cell of
    a sheet, you can for example use...

    ThisWorkbook.Worksheets("Sheet1").Range("X42").Value = ListBox2.List(0, 0)
    ... where X42 is the cell and List(0 = the Index = row,0 = the Column Number)
    is the first item in the first column of the listbox.

    By the way, I have some suggestions for your code: You have declared some variables
    at the end of the code module of the userform (Dim a, b, c, ...). This will lead to a
    compile error. It is better to declare all these variables at the top of the module.
    And it will be great to also give them a type, for example:
      Dim a As String
      Dim b As String
    ' ...
    In this example, a and b are declared as Strings here, as you are assigning to
    a the value = "LookUpList!A2:A9", which is a string.

    Regards :-)

  3. #3
    thanks. i also noticed there is some error in my code because of the variable declaration.

Posting Permissions

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