Range based on length of list for Combobox

jonnn21

New Member
Joined
Feb 9, 2012
Messages
23
I have a Pivot table that has a list of items.
This list is produced from a Categories column
As more categories are added, this pivottable gets longer

I have a combobox that shows all of the items in this Pivottable

Currently this is the code I use for the combobox list:
Me.CmboCategory.List = Worksheets("1 parts").Range("AB2:AB25").Value

I would like to make the Range("AB2:AB25").Value change based on the exact length of the pivot table
so it would go from Range("AB2:AB25").Value to Range("AB2:AB26").Value ect ect... depending on how many other categories are added later on.

I thought I could cheat and just make a string:
listrng = "Worksheets(""1 parts"").Range(" & """AB2:" & "AB" & Range("ac2").Value & """).value"
In which produces: Worksheets("1 parts").Range("AB2:AB23").value

Then use Me.CmboCategory.List = listrng
But that doesnt work.

Basically I want the list length of my combobox to be the exact number of items in my pivottable
Thanks in advance!
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
For reference if anyone else needs this:

With Sheets("1 parts")

Me.CmboCategory.List = .Range("AB2", .Range("AB" & .Rows.Count).End(xlUp)).Value

End With

1 Parts is the Worksheet the table is located
CmboCategory is the combobox
AB2 is the first cell in the list

Sorry for the LOOOONG explanation of the problem but at least it was a simple solution :)
 
Upvote 0

Forum statistics

Threads
1,213,552
Messages
6,114,278
Members
448,559
Latest member
MrPJ_Harper

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