我有一个简单的for-next来填充用户表单上的一些标签,但是无法弄清楚为什么不断获得“错误1004”当我输入Contr.Caption时,.Caption函数丢失了?
Dim Control_Name As String
Dim DSlot As Long
Dim DLName As Long
Dim Contr As Control
With Worksheets("apartments").Range("depositslot")
DSlot = .Find("Slot").Row + 1
DLName = .Find("Last").Column
End With
For Each Contr In Layout.Controls
If TypeName(Contr) = "Label" Then
Control_Name = Mid(Contr.Name, 1, 6)
If Control_Name = "LBName" Then
Contr.Caption = Worksheets("apartments").Range(DSlot, DLName).Value
DSlot = DSlot + 1
End If
End If
Next
答案 0 :(得分:5)
你的话说:
Contr.Caption = Worksheets("apartments").Range(DSlot, DLName).Value
应该是
Contr.Caption = Worksheets("apartments").Cells(DSlot, DLName).Value
Range
属性不接受Long
类型的两个参数。
答案 1 :(得分:2)
尝试更改"范围"对象由#34; Cells",因为你有"行,列"的引用。你应该有这样的东西:
Contr.Caption = Worksheets("apartments").Cells(DSlot, DLName).Value