DATA Validation without blanks

KDS14589

Board Regular
Joined
Jan 10, 2019
Messages
182
Office Version
  1. 2016
Platform
  1. Windows
In a Data Validation List, I have as source a name range called ‘Controls_Add_Items_to_Selector’ that has the following formula



VBA Code:
=OFFSET(Controls.General!$P$5,0,0,COUNTA(Controls.General!$G$5:$P$300),1)



It is based on data from cells 5 to 300 in column P of which currently only 5 to 35 have data.

Problem is it gives the data from 5 to 35 but also show blanks up to 300.



This is an ‘old style’ formula I was using that gave me just the data cells only (5 to 35 or more/less).



VBA Code:
=Controls.General!$P$5:INDEX(Controls.General!$P$5:$P$300,COUNTIF(Controls.General!$P$5:$P$300,"?*"))



Somewhere in time I started using the ‘offset’ but just now noticed the difference. Can I modify the ‘offset’ or should I go back to the other if I don’t want blanks in the list.
 

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.
Offset is not the problem here, COUNTA counts all cells that are not empty (which includes formulas that show a blank cell). If you use COUNTIF, as you have in the other formula then it should work as required.

In most cases I would give preference to INDEX over OFFSET but for what you are doing here there is no advantage or disadvantage to either method.
 
Upvote 0
Solution
In a Data Validation List, I have as source a name range called ‘Controls_Add_Items_to_Selector’ that has the following formula



VBA Code:
=OFFSET(Controls.General!$P$5,0,0,COUNTA(Controls.General!$G$5:$P$300),1)



It is based on data from cells 5 to 300 in column P of which currently only 5 to 35 have data.

Problem is it gives the data from 5 to 35 but also show blanks up to 300.



This is an ‘old style’ formula I was using that gave me just the data cells only (5 to 35 or more/less).



VBA Code:
=Controls.General!$P$5:INDEX(Controls.General!$P$5:$P$300,COUNTIF(Controls.General!$P$5:$P$300,"?*"))



Somewhere in time I started using the ‘offset’ but just now noticed the difference. Can I modify the ‘offset’ or should I go back to the other if I don’t want blanks in the list.
Just wondering, you have a $G$5 in your first Offset - is that meant to be $P$5?
 
Upvote 0
Offset is not the problem here, COUNTA counts all cells that are not empty (which includes formulas that show a blank cell). If you use COUNTIF, as you have in the other formula then it should work as required.

In most cases I would give preference to INDEX over OFFSET but for what you are doing here there is no advantage or disadvantage to either method.
Thanks for reply.
I don't know when I started the 'offset' but if there's no difference I'll go back to the 'index' (my favorite anyway)
AGAIN THANKS
 
Upvote 0

Forum statistics

Threads
1,214,944
Messages
6,122,391
Members
449,080
Latest member
Armadillos

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