Using Variables in .RowSource

AlanAnderson

Board Regular
Joined
Jun 7, 2010
Messages
134
Hi,
I have a spreadsheet where not only can the amount of rows increase but so can the columns being used.
I need to reference parts of this area with a list box but am having difficulty in assigning cvariables to the rowsource.
Code:
Private Sub UserForm_Initialize()
Dim FinalRow As Long
Dim FinalCol As Long
    With Me.ListBox1
    .boundcolumn = 1
    .columncount = FinalCol
    .columnheads = True
    .textcolumn = True
   .rowsource = "A1:K50"  'Thats what it currently is
  '  .rowsource = vStart & 1 & ":" & FinalCol & FinalRow ' No form of this is working
    .ListIndex = 0
    End With
 
End Sub
My problem is that only the "1" from A1 is constant, the "A' would be supplied by a variable such as vStart whilst the "K" from last column and the 50 from Last Row.

Can this be done?

Regards,

Alan
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Try:

Code:
.rowsource = Range(Cells(1,vStart),Cells(FinalRow,FinalCol)).Address (False, False)
 
Upvote 0
Hi, A further question, is it possible to populate ther List box with say Cols 1 to 4 and then say cols 20 to 30 (called "vStart" and vEnd" ???

Regards,

Alan
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top