VBA RowSource with variable

0

How do I put a variable worksheet in a RowSource? I am trying to concatenate with the last line but it is giving error:

Private Sub UserForm_Initialize()
Dim plan As Worksheet
Dim lin As Range
Dim fim As Range

Optionapos = True

If Optionapos = True Then
    Set plan = Worksheets("CadReu")
Else
    Set plan = Worksheets("CadReuOlde")
End If

With plan

'atualiza a caixa localizar
Dim totaldelinhas As Integer
totaldelinhas = plan.UsedRange.Rows.Count

'formreunioes.cxLocalizar2.ColumnCount = .Columns.Count
formreunioes.cxLocalizar2.RowSource = .Range("A1:A" & totaldelinhas)

End With
    
asked by anonymous 29.01.2017 / 16:42

1 answer

1

I solved by changing the code above all the type of the plan variable The Worksheet for for string and worked, as follows:

Private Sub UserForm_Initialize()
Dim plan As String
Dim lin As Range
Dim fim As Range

Optionapos = True

If Optionapos = True Then
plan = "CadReu"
Else
plan = "CadReuOlde"
End If

'atualiza a caixa localizar
Dim totaldelinhas As Long
totaldelinhas = Worksheets(plan).UsedRange.Rows.Count

formreunioes.cxLocalizar2.RowSource = plan & "!" & "A2:A" & totaldelinhas
    
23.03.2017 / 19:29