首页 > 解决方案 > 如何使用用户窗体从列表框中插入列单元格?

问题描述

我有 PHP 和 .Net 的背景,但我是 VBA 新手。是否可以在来自用户表单的列表框的 excel 中添加特定的列单元格?谢谢。

标签: excelvba

解决方案


我已经设法插入一个来自用户表单的新列。这是我的代码。

Private Sub btnSaveParameters_Click()

    Dim totalParameters As Integer
    totalParameters = ListBox1.ListCount

    Dim lColumn As Long
    Dim addlColumn As Long
    Dim ws As Worksheet
    Set ws = Worksheets("Reference")
    Dim i As Integer
    i = 0
    Do Until i >= Me.ListBox1.ListCount
        MsgBox "The vaue of i is: " & ListBox1.List(i)
        lColumn = ws.Cells(3, ws.Columns.Count).End(xlToLeft).Column
        addlColumn = lColumn + 1
        ws.Cells(3, addlColumn).Value = Me.ListBox1.List(i)
        i = i + 1
    Loop
End Sub

推荐阅读