how to display content in excel sheet using listbox rowsource vba

tkfei

New member
Joined
Jun 10, 2011
Messages
2
Reaction score
0
Points
0
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.
thanks.
 

Attachments

  • sample.xls
    85.5 KB · Views: 648
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...

Code:
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:
Code:
  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 :)
 
thanks. i also noticed there is some error in my code because of the variable declaration. :)
 
Back
Top