Reputation: 175
I have a simple for-next to fill some labels on a userform but can not figure out why a keep getting a " Error 1004" When I type the Contr.Caption the .Caption function is missing?
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
Upvotes: 1
Views: 84
Reputation: 307
Try changing the "Range" object by "Cells", since you have references of "Row, Column". You should have something like this:
Contr.Caption = Worksheets("apartments").Cells(DSlot, DLName).Value
Upvotes: 2
Reputation: 23994
Your line saying:
Contr.Caption = Worksheets("apartments").Range(DSlot, DLName).Value
should be
Contr.Caption = Worksheets("apartments").Cells(DSlot, DLName).Value
The Range
property does not accept two parameters of type Long
.
Upvotes: 5