0
这是我到目前为止,只有一列的数据,我想提取它并写在一个特定的单元格中(如:sheet14.cells(45,2).value)Excel(VBA,Userform)如何将Listbox中的数据添加到特定的单元格?
谢谢你的帮助。
这是我到目前为止,只有一列的数据,我想提取它并写在一个特定的单元格中(如:sheet14.cells(45,2).value)Excel(VBA,Userform)如何将Listbox中的数据添加到特定的单元格?
谢谢你的帮助。
假设你的意思是你想提取物从一个ListBox数据到特定的细胞
,这里是我的答案
用户窗体的代码中放一个按钮功能
Private Sub CommandButton1_Click()
Dim i 'to store the item of the list
Dim j 'Just a counter
j = 0 'Ini the counter
For Each i In Me.ListBox1.List 'Ini the for loop
j = j + 1 'Add one to the counter
Cells(j, 4).Value = i 'here is the thing.
'In the cell(row = j, column = 4 = D) put the value: i = the item of the list
'This take all the items of the list, inside the combobox.
Next i 'Next one please!
End Sub
编辑#1
阅读(老化)你的问题,看到你想写一个不活动的表中的列表......好吧,在这里!
Private Sub CommandButton1_Click()
Dim i 'to store the item of the list
Dim j 'Just a counter
Dim sht As Worksheet 'the var for the sheet you want
Set sht = Sheets("S")
'the name of the sheet I want is "S", stored inside the var sht
j = 0 'Ini the counter
For Each i In Me.ListBox1.List 'Ini the for loop
j = j + 1 'Add one to the counter
sht.Cells(j, 4).Value = i 'here is the thing.
'In the cell(row = j, column = 4 = D)
'put the value: i = the item of the list
'This take all the items of the list, inside the combobox.
Next i 'Next one please!
End Sub
编辑#2
现在你可以在ListBox中使用它。而且这种改变非常简单,只需擦除ComboBox1并编写“ListBox1”,它就可以与这两个控件一起使用。
编辑#3
有了这个代码,你把所有的单个细胞
Private Sub CommandButton1_Click()
Dim i 'to store the item of the list
Dim j 'Just a counter
Dim sht As Worksheet 'the var for the sheet you want
Set sht = Sheets("S")
'the name of the sheet I want is "S", stored inside the var sht
j = 0 'Ini the counter
For Each i In Me.ListBox1.List 'Ini the for loop
j = j + 1 'Add one to the counter
sht.Cells(1, 4).Value = sht.Cells(1, 4).Value & Chr(10) & i
'here is the thing.
'In the cell(row = 1, column = 4 = D)
'put the value: i = the item of the list
'besides the others values.
'Everything inside a single cell
'This take all the items of the list, inside the combobox.
Next i 'Next one please!
End Sub
里面,如果你需要一些改进告诉我。
它是一个列表框,你知道该怎么做吗? –
检查我的编辑#2,我做了更改,并注意该代码适用于组合框和列表框。 –
而且变化非常简单,只需查看两个控件的属性就可以了解需要进行哪些更改。如果你想要更多有关这些控件的文档,你可以看看这些控件可以在VBA中完成。或者只是写下控件的名称,然后指向可用属性的列表。 –