Increase the list fill range with vba

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,330
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

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
17,651
Office Version
  1. 2013
Platform
  1. Windows
What is YPNames

Is this a Named Range or a Sheet Name
Is this Listbox on a sheet or a Userform.
 

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
17,651
Office Version
  1. 2013
Platform
  1. Windows
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
 

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,330
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Thanks for the reply, it is using a combo box and YPNames is the sheet name
 

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,330
Office Version
  1. 365
  2. 2016
Platform
  1. Windows

ADVERTISEMENT

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
 

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,330
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
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
 

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
20,353
Office Version
  1. 2016
  2. 2013
  3. 2007
Platform
  1. Windows

ADVERTISEMENT

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
 

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,330
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
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.
 

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
20,353
Office Version
  1. 2016
  2. 2013
  3. 2007
Platform
  1. Windows
Rich (BB code):
variable not defined, with cboYP highlighted
....means you didn't declare cboYP
 

Watch MrExcel Video

Forum statistics

Threads
1,132,898
Messages
5,655,858
Members
418,248
Latest member
JinxedCaspa

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
Top