Increase the list fill range with vba

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,352
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
How do I increase the list fill range so that when I add items to my list, a combo box that has a list of the items in it is updated automatically. The Listfillrange property of my combo box is YPNames!$A$2:$A48 but I want it to be A2 to the bottom of the list on YPNames.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
What is YPNames

Is this a Named Range or a Sheet Name
Is this Listbox on a sheet or a Userform.
 
Upvote 0
This script will do what you want but to have this run automatically when you add a value to the range. Would take more work.
VBA Code:
Private Sub CommandButton1_Click()
'Modified  5/11/2021  10:27:23 PM  EDT
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
ListBox1.List = Range("A2:A" & Lastrow).Value
End Sub
 
Upvote 0
Thanks for the reply, it is using a combo box and YPNames is the sheet name
 
Upvote 0
I changed to the name of the combo box but i get the error of variable not defined, with cboYP highlighted. This is the name of my combo box

VBA Code:
Sub AddNameList()
    Dim Lastrow As Long
    Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
    cboYP.List = Range("A2:A" & Lastrow).Value
End Sub
 
Upvote 0
With this code I get the error permission denied.

VBA Code:
Sub AddNameList()
    Dim Lastrow As Long
    Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
    Tracker.cboYP.List = Range("A2:A" & Lastrow).Value
End Sub
 
Upvote 0
Have you got Option Explicit turned on ??
VBA Code:
Sub AddNameList()
   cboYP.List = Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row).Value
End Sub
 
Upvote 0
I think I need to update the list fill range property to be 1 greater in column A using vba but I am not sure how to do that.
 
Upvote 0
Rich (BB code):
variable not defined, with cboYP highlighted
....means you didn't declare cboYP
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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