Journal of a guy who loves Excel

Not only about Excel, but also daily stuff to kill my boredom.

Filling a ListBox Control (ActiveX)

In our forum, I answerd a question about ListBox control fo Excel.
http://puremis.net/excel/cgi-bin/yabb/YaBB.pl?num=1225116333

As additional tips, I'm writing this.

First of all, there are 2 kinds of controls for use in Excel worksheets.
The one is a contorl belongs to Forms, another is belongs ControlToolBox which is called ActiveX control. ActiveX control has been implemented since Excel 97, as the new control set which has more ritch functions.

This time, I'm talking about is ActiveX.

Since there are many ways to fill a ListBox control, it's depends that which way you should use for.


#1:ListFillRange


When the values which you'd like to fill a ListBox control have been placed in a worksheet, using the ListFillRange property would be the most easiest way.


ListBox1.ColumnCount = 2
ListBox1.ListFillRange = "Sheet1!A1:B10"



#2:AddItem


This is the most poplar way to add values one by one.


ListBox1.AddItem "item1"
ListBox1.AddItem "item2"


#3:List


If you have an array, you can simply set it as the List property.
The array shoud be a 2-d array. If already the ListFillRange has been set, you have to remove before execute this.


arr = Range("A1:B10").Value
ListBox1.Clear
ListBox1.ColumnCount = 2
ListBox1.List = arr



#4:Column


You can use the Column property as same as List property.
The difference is the Row and the Column are switched.


arr = Range("A1:B10").Value
ListBox1.Clear
ListBox1.ColumnCount = 10
ListBox1.Column = arr

 | HOME | 

calendar

10 | 2009/11 | 12
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 - - - - -



recent comments




recent entries




categories




links




search




DTIブログ
ブログでアフィリエイト


DTIブログポータルへ

このブログを通報

profile

Colo

Author:Colo

Colo aka Masaru - one of the Microsoft MVP for Excel

WEB SITE



My name is Masaru Kaji and I am from Kobe, Japan. I was born on 9th Jan 197x. I'm a computer system administrator for an equipment manufacturer. My line is operation AS400 server and Windows2000 server. I sometimes write VBA code for the company. It was in March 2000, that I first met Microsoft Excel. In my job, my superior forced me into creating something like an address book. At that time, my main machine was not a personal computer but a word processor. And I had not used a personal computer for about 10 years. Until then also I had never used any spreadsheet software.. The first time I used Excel, I remember thinking 'Wow! What a cool application it is!, If I were able to use it as I want, it makes my job easier.'

Back to the subject about my work, I was making some easy tables that has similar data, but it made me bored because I have to input same thing again and again. I am not a patient character. :) When I was doing something with Excel, a menu named 'Record New Macro' was found, and by using this menu, I discovered unexpectedly that my operation was recorded.

I could imagine the function from the meaning of a word in the code generated automatically somehow, so I made some macros for my job without installing VBA help. In fact I did NOT know how to see Help file.

Gradually, I had come to want to do that was not possible to do in a 'Record New Macro' alone and I determined installing a VBA help file. (I said goodbye to my slow to act.) But the descriptions written in Help file were too difficult for me to understand. Then, in order to solve the question, which I cannot understand by Help, I posted my question to Japanese QA site on www.


And as you know, I'm not good at English, so in order to learn English and to learn technical terms, I begun to post to MrExcel. I am still learning... :)

In 2004, I was nominate as a Microsoft Excel MVP, and in 2005, fortunately I was re-nominated again.




.
I'm a PEG-UX50 owner!

1 Click Animalsへ!
Have a look at this article pls.

Our book
Our book

contributed article
contributed article

contributed article
contributed article

contributed article
contributed article


archive


rss feeds