listbox

Excel VBA multi column listbox add item on top

社会主义新天地 提交于 2020-07-22 14:12:08
问题 All, is there any easy way to add item at begining of listbox? I found some information about insert function but it seems to be not available in Excel VBA. Only way I found is to create FOR which will move each row to +1 postion and then insert item at 0 index. I was really hoping there is a easier way. My long version looks like this: Sub InsertRecordAtTheTop(sText1, sText2) Dim i With lbCases If .ListCount > -1 Then .AddItem "0" ''' add new row For i = .ListCount - 1 To 1 Step -1 ''' move

Excel VBA multi column listbox add item on top

浪子不回头ぞ 提交于 2020-07-22 14:12:07
问题 All, is there any easy way to add item at begining of listbox? I found some information about insert function but it seems to be not available in Excel VBA. Only way I found is to create FOR which will move each row to +1 postion and then insert item at 0 index. I was really hoping there is a easier way. My long version looks like this: Sub InsertRecordAtTheTop(sText1, sText2) Dim i With lbCases If .ListCount > -1 Then .AddItem "0" ''' add new row For i = .ListCount - 1 To 1 Step -1 ''' move

Clear items selected from ListBox

*爱你&永不变心* 提交于 2020-07-11 06:18:12
问题 I am trying to create a simple form using an Excel macro. This form will be used to input data which will be stored in Sheet2. Once the data has been saved, I would like to clear the contents from the form. I have been able to achieve this for most of the input boxes except for listbox. Below is the code that through which I am trying to achieve this functionality. Dim clearlstbox As Long With AOI For clearlstbox = .ListCount - 1 To 0 Step -1 If .Selected(clearlstbox) = True Then .RemoveItem

Clear items selected from ListBox

浪子不回头ぞ 提交于 2020-07-11 06:15:43
问题 I am trying to create a simple form using an Excel macro. This form will be used to input data which will be stored in Sheet2. Once the data has been saved, I would like to clear the contents from the form. I have been able to achieve this for most of the input boxes except for listbox. Below is the code that through which I am trying to achieve this functionality. Dim clearlstbox As Long With AOI For clearlstbox = .ListCount - 1 To 0 Step -1 If .Selected(clearlstbox) = True Then .RemoveItem

How to resize a Win32 listbox to fit its content?

爱⌒轻易说出口 提交于 2020-07-10 17:41:29
问题 Is there any way to resize a Win32 listbox to fit its content (the minimum size that will show all its content, not needing a scrollbar), whenever its items change? Thank! Edit: I need resize both width and height of listbox. 回答1: You didn't specify whether you wanted horizontal as well as vertical, but I'm going to assume not. Basically, you need to get the number of items and the item height and multiply them, then add on the space for the control borders (unless the control is borderless,