Solved

Delphi: data validation in Excel, Formula1 not fix

Posted on 2013-11-21
4
895 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 500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

696 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