Tag: listbox

Excel多选,多列列表框

我无法编码一个用户窗体,从一个多列列表框中select的数据,并将其添加到同一个用户的另一个列表框。 添加后,数据将从源列表框中删除 “ListBox”是数据所在的位置,“listbox1”是它被添加到的位置。 Private Sub add_Click() For i = 0 To ListBox.ListCount – 1 If ListBox.Selected(i) = True Then NextEmpty = ListBox1.ListCount ListBox1.List(NextEmpty, 0) = ListBox.List(i, 0) ListBox1.List(NextEmpty, 1) = ListBox.List(i, 1) ListBox1.List(NextEmpty, 2) = ListBox.List(i, 2) ListBox.RemoveItem (i) End If Next End Sub 此代码给我一个运行时错误“381”无法设置列表属性。无效的属性数组索引。 我已经做了一些四处张望,但似乎无法确定如何正确使用这些属性。 任何帮助是极大的赞赏。

将列表框中的项目导出到Excel中的范围

所以我已经search谷歌和论坛后(包括堆栈)试图找出这个问题。 我想要做的是有一个ActiveXbutton将列表框的内容导出到Excel中的范围。 下面是我添加ListBox1到ListBox2项目的代码。 当所有需要的项目被移动到ListBox2后,所述的ActiveXbutton(SomeButton_Click)将把列表框2中的所有项目导出到从范围(“a1”)开始的“Sheet15”。 (请注意,这是一个不在实际表单中的ActiveX列表框,它在工作表中) Public Sub BTN_MoveSelectedRight_Click() Dim iCtr As Long Dim n As Long, lRow As Long Dim cStartCell As Range For iCtr = 0 To Me.ListBox1.ListCount – 1 If Me.ListBox1.Selected(iCtr) = True Then Me.ListBox2.AddItem Me.ListBox1.List(iCtr) End If Next iCtr For iCtr = Me.ListBox1.ListCount – 1 To 0 Step -1 If Me.ListBox1.Selected(iCtr) = […]

将数据返回到单元格范围

以下代码允许来自表单元格范围的数据: Private Sub UserForm_Initialize() listTo.Clear listCC.Clear listTo.List = Worksheets("Main").Range("C12:C26").Value listCC.List = Worksheets("Main").Range("D12:D26").Value End Sub 这工作正常。 那么现在我的问题是如果用户点击Updatebutton,如何将它们返回到工作表。 我在这里find了一些答案,但我看不到任何更改或似乎不工作。 以下是我编辑的代码: Private Sub btnUpdate_Click() Dim dataItems As Range With Me.listTo Dim Data() ReDim Data(1 To .ListCount, 1 To 1) Data = .List With Worksheets("Main") Set dataItems = .Range("C12", .Range("C12").Offset(Me.listTo.ListCount – 1, 0)) End With With dataItems .Value = […]

筛选列表框只在Excel中包含唯一值

我有一个简单的Excel / VBA问题: 我想创build的是一个(单选)列表框,我想在不同的工作表上显示数据的唯一值。 到目前为止,我有一个像这样的ListBox: 而我想要显示的数据的命名select: 我使用了这样的公式,并用它作为ListBox的input。 公式:= BEREICH.VERSCHIEBEN(TopicData!$ C $ 1; 1; 0; ANZAHL2(TopicData!$ C:$ C)-1; 1) 现在我的问题是:我怎样才能让列表框显示唯一的值? 我熟悉vba,所以包含这个的解决scheme将是完全正确的。 事实上,我已经尝试删除vba中的重复条目,每当有一个ListBox的变化,但由于某种原因似乎没有任何工作。 这是我的vba脚本,我试图解决这个问题: unfortunatley我总是得到一个“错误400”,当我调用ListBox的RemoveItem 。 ' … ' filter listbox content so only unique values remain Dim i As Integer ' find duplicates Dim inList As New Collection Dim indexesToRemove As New Collection For i = […]

无法从Excel用户窗体中的多选ListBox中列出所选项目

新的VBA和从列表框中获取选定的项目有一些困难。 我一直在For线上发生错误。 列表框的名称是正确的,我想.ListCount应该工作。 Sub GetListBox1() Dim SelectedItems As String For i = 0 To ListBox1.ListCount – 1 If ListBox1.Selected = True Then SelectedItems = SelectedItems & ListBox1.List(i) End If Next i Debug.Print SelectedItems End Sub

在listbox vba中find所选项目的一行#

我怎样才能find列表框中选定项目的行#? 现在我有一个subinput所有find的项目列表框,见下文 Sub findnext() Dim Name As String Dim f As Range Dim ws As Worksheet Dim s As Integer Dim findnext As Range Set ws = ThisWorkbook.Worksheets("Master") Name = surname.Value ListBox1.Clear Set f = Range("A:A").Find(what:=Name, LookIn:=xlValues) Set findnext = f Do Debug.Print findnext.Address Set findnext = Range("A:A").findnext(findnext) ListBox1.AddItem findnext.Value ListBox1.List(ListBox1.ListCount – 1, 1) = […]

如何获得一个列表框,将结果返回到excel vba中的下一个空行

我有一个包含40个项目的列表框。 我想要达到的目的是让每一个被选中的每一个都在其单独的行中被返回,并且在它们之间缺less一行,因此.Row + 2 。 示例代码是: Dim LastRow As Long Dim lItem As Long LastRow = Worksheets(3).Range("B" & Rows.Count).End(xlUp).Row + 2 For lItem = 0 To ListBox1.ListCount – 1 If ListBox1.Selected(lItem) And lItem = 0 Then Worksheets(3).Range("B" & LastRow).Value = "Example1abc" ElseIf ListBox1.Selected(lItem) And lItem = 1 Then Worksheets(3).Range("B" & LastRow).Value = "Example2def" ElseIf ListBox1.Selected(lItem) […]

清除从列表框中select的项目

我正在尝试使用Excelmacros创build一个简单的表单。 这个表单将被用于input将被存储在Sheet2中的数据。 数据一旦保存,我想清除表格中的内容。 我已经能够实现这个大多数的input框,除了列表框。 下面是通过我试图实现这个function的代码。 Dim clearlstbox As Long With AOI For clearlstbox = .ListCount – 1 To 0 Step -1 If .Selected(clearlstbox) = True Then .RemoveItem clearlstbox End If Next clearlstbox End With ' 'For clearlstbox = AOI.ListCount – 1 To 0 Step -1 ' If AOI.Selected(clearlstbox) = True Then ' AOI.RemoveItem (clearlstbox) ' […]

listcount -1的含义是什么?

我一直在寻找互联网试图find什么意思listcount -1是,但我似乎无法find确切的答案。 为什么在listcount旁边有-1 ? 或.list(.listcount -1,1)是什么意思? 编辑 listcount的例子 .additem a.value .list(.listcount -1, 1) = ws.cells(A,B).value 这将ws.cells(A,B)的值添加到listbox1,但我不明白为什么/如何? 或者我在互联网上find一个code http://www.ozgrid.com/VBA/multi-select-listbox.htm 我明白代码的目的是“如果其中一个列表被选中,然后将列表框的值传递到单元格”,但为什么有.Listbox1.Listcount -1 ?

Excel VBA中的ListBox中的持久值

这是我在这个论坛的第一个问题,我对Excel VBA很新颖。 我有一个文本框有一个Exit事件。 我的要求是,当我填充该文本框,并从那里退出它的值应填充在ListBox中。 现在,当我试图在文本框中再次插入值时,它会覆盖ListBox中的以前的值。 我想要的价值是持久的。 所以在文本框中input的值应该按顺序排列。 这是我试过的: ListBox1.ColumnCount = 2 ListBox1.AddItem ListBox1.List(0) = TextBox2.Text 但是,那么我怎样才能从文本框中的下一个值,并使其在列表框中显示…(所以如果我在文本框中input3个值,它应该在列表框中显示三行)