将内容插入到列表框VBA Excel中. [英] Insert content into listbox VBA Excel.
本文介绍了将内容插入到列表框VBA Excel中.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数据库,其字段名为"Varernumrer"(产品编号).在此字段中,我写了几个数字,以,(逗号)分隔.我现在想将这些数字加载到列表框中.
到目前为止我的代码:
I have a database with a field called "Varernumrer" (Productnumbers). In this field i have written several numbers, seperated by , (comma). I now want to load these numbers into a listbox.
My code so far:
Private Sub CommandButton2_Click()
With rsFaktura
UserForm1.ListBox1.AddItem !Varenumrer
End With
End Sub
但这只是获取整个文本并将其放在列表框的第一行.
我使用MS Office 2007程序.
希望任何人都能帮助我.
But that just gets the entire text and puts it in the first line of the listbox.
I use MS Office 2007 programs.
Hope anyone can help me.
推荐答案
您可以在临时工作表上的一系列单元格中填充列表框.
现在,您必须提供代码来解析该字符串,从中获取每个值并将它们一个一地添加到ListBox中.
You can populate a ListBox from a Range of cells on a scratch worksheet.
The way you''re doing it now, you would have to supply code to parse that string, getting each value out of it and adding them, one-by-one to the ListBox.
我自己找到了解决方案.
代码是:
I have found the solution myself.
the code is:
Lines = Split(rsFaktura.Fields("Varenumrer"), ",")
num_rows = UBound(Lines)
Do While I <= num_rows
Line = Split(Lines(I), ",")
Line1 = Line(0)
ListBox1.AddItem (Line1)
Ark1.Cells(11, I + 15) = Line
I = I + 1
Loop
这篇关于将内容插入到列表框VBA Excel中.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文