?
Solved

Delphi: data validation in Excel, Formula1 not fix

Posted on 2013-11-21
4
Medium Priority
?
911 Views
Last Modified: 2013-11-21
Hi

I want to validate some cells (accept only values from a list).
            ExcelApp.Range['A1','A1'].EntireColumn.Validation.Add(Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:='=$D$1:$D$45');

Open in new window

With Delphi I fill in the values in column D. The number of values differs, so I can not set "Formula1:='$D$1:$D$45'" (45 may be different each time). How can I solve this that $D$45 is variable?

Thanks, Peter
0
Comment
Question by:formi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 33

Accepted Solution

by:
Rob Henson earned 2000 total points
ID: 39666694
Create a dynamic range name for your list of valid entries.

Assuming list on Sheet1 and nothing but list of entries in column D, the following can be used in the name manager to create a dynamic range:

=OFFSET(Sheet1!$D$1,0,0,COUNTA(Sheet1!$D:$D),1)

You would then change your VBA to refer to the Named Range.

Thanks
Rob H
0
 

Author Closing Comment

by:formi
ID: 39667306
As I have the german version of Excel I had to change the , by ;

now it works with the following call (thank you for your help!):

ExcelApp.ActiveWorkbook.Names.Add('artgr', '=neu_nouveaux!$F$1:OFFSET(neu_nouveaux!$F$1;0;0;COUNTA(neu_nouveaux!$F:$F);1)');

I tried it with the param-names (Name:= and RefersToR1C1:=) inside as in other functions but I got an error "error in formula". Maybe you now why?? See below

ExcelApp.ActiveWorkbook.Names.Add(Name='artgr', RefersToR1C1:='=neu_nouveaux!$F$1:OFFSET(neu_nouveaux!$F$1;0;0;COUNTA(neu_nouveaux!$F:$F);1)');
0
 
LVL 33

Expert Comment

by:Rob Henson
ID: 39667624
The OFFSET function should replace the whole if the Refers to formula, not $F$1:OFFSET(...).

The offset function creates the range.
0
 

Author Comment

by:formi
ID: 39668162
ok, when I use OFFSET only it works if I use RefersTo (not RefersToR1C1. Thanks
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa‚Ķ

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question