Solved

Delphi: data validation in Excel, Formula1 not fix

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

Technology Partners: 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

Suggested Solutions

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

726 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