View Full Version : how to display content in excel sheet using listbox rowsource vba
2011-06-10, 03:07 AM
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.
2011-06-10, 10:40 AM
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.
2011-06-10, 11:57 AM
thanks. i also noticed there is some error in my code because of the variable declaration. :)
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.