【发布时间】:2015-03-20 21:39:17
【问题描述】:
我是一名初级程序员,正在为我的高级顶点项目制作 VBA 宏。我正在尝试使用“A 列”中的数据填充列表框。它必须是动态的,因为用户将编辑数据。我知道对于经验丰富的编码人员来说这很简单,但我遇到了语法问题。任何帮助是极大的赞赏!
Private Sub UserForm_Initialize()
Dim LastRowControllers, LastRowBrakes As Integer
Dim Brakes, Controllers As Range
With Worksheets("ControllersInventory")
LastRowControllers = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
With Worksheets("BrakesInventory")
LastRowBrakes = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
Set Controllers = Range(Cells(1, 1), Cells(LastRowControllers, 1))
Set Brakes = Range(Cells(1, 1), Cells(LastRowBrakes, 1))
'Populate Controller_List
Worksheets("ControllerInventory").Select
With Controller_List
.RowSource "= Controllers"
End With
'Populate Brake_List
Worksheets("BrakeInventory").Select
With Brake_List
.RowSource "= Brakes"
End With
End Sub
我找到了另一种填充列表框的方法,但是我的语法错误,我想通过使用声明的范围来使用正确的编码技术。
Brake_List.RowSource = Worksheets("BrakeInventory").Range(Cells(1, 1), Cells(LastRowControllers, 1)).Address
【问题讨论】:
-
尝试将
.address更改为.value