ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Trying to demo Code, but get error (https://www.excelbanter.com/excel-programming/380333-trying-demo-code-but-get-error.html)

JMay

Trying to demo Code, but get error
 
On page 189 of Excel 2003 Programming - Inside/Out an
Example is given to set Validation criteria for 10 cells in Column C

Before Entering anything into cells C2:C11 I created (in a std module):

Sub Tester()
With ActiveSheet.Range("C2:C11").Validation
..Add Type:=xlValidateWholeNumber, AlertStyle:=xlValidAlertStop, _
Operator:=xlLessEqual, Formula1:="5000"
..InputTitle = "Credit Limit"
..ErrorTitle = "Credit Limit too High"
..InputMessage = "Enter the Customer's Credit Limit."
..ErrorMessage = "The Credit limit must be less than $5,000."
End With
End Sub

Stepping thru the code I get a R/T error 1004;
Can anyone assist me in determining why?

There doesn't seem to be any errata available for this book.

TIA,

Jim May


Bob Phillips

Trying to demo Code, but get error
 
Jim,

It worked fine for me.

Is the worksheet protected perchance?

--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"JMay" wrote in message
...
On page 189 of Excel 2003 Programming - Inside/Out an
Example is given to set Validation criteria for 10 cells in Column C

Before Entering anything into cells C2:C11 I created (in a std module):

Sub Tester()
With ActiveSheet.Range("C2:C11").Validation
.Add Type:=xlValidateWholeNumber, AlertStyle:=xlValidAlertStop, _
Operator:=xlLessEqual, Formula1:="5000"
.InputTitle = "Credit Limit"
.ErrorTitle = "Credit Limit too High"
.InputMessage = "Enter the Customer's Credit Limit."
.ErrorMessage = "The Credit limit must be less than $5,000."
End With
End Sub

Stepping thru the code I get a R/T error 1004;
Can anyone assist me in determining why?

There doesn't seem to be any errata available for this book.

TIA,

Jim May




Dave Peterson

Trying to demo Code, but get error
 
If I ran it a second time, I got an error -- it's trying to add validation rules
to a range that already has rules.

But you could add a line to delete any existing rules before you add the new
ones:

With ActiveSheet.Range("C2:C11").Validation
.Delete
....rest of code

JMay wrote:

On page 189 of Excel 2003 Programming - Inside/Out an
Example is given to set Validation criteria for 10 cells in Column C

Before Entering anything into cells C2:C11 I created (in a std module):

Sub Tester()
With ActiveSheet.Range("C2:C11").Validation
.Add Type:=xlValidateWholeNumber, AlertStyle:=xlValidAlertStop, _
Operator:=xlLessEqual, Formula1:="5000"
.InputTitle = "Credit Limit"
.ErrorTitle = "Credit Limit too High"
.InputMessage = "Enter the Customer's Credit Limit."
.ErrorMessage = "The Credit limit must be less than $5,000."
End With
End Sub

Stepping thru the code I get a R/T error 1004;
Can anyone assist me in determining why?

There doesn't seem to be any errata available for this book.

TIA,

Jim May


--

Dave Peterson

JMay

Trying to demo Code, but get error
 
Thanks Guys and A Happy New Year to 'ya
Obviously, I was running more than Once;
The .Delete remedied it

Is there a way I can (In the Immediate window)
Determine the current Validation range (C2:C11)
Like:
? ValidationRange.Address
C2:C11 <<Results

Thanks,

Jim May


" wrote in message
:

If I ran it a second time, I got an error -- it's trying to add validation rules
to a range that already has rules.

But you could add a line to delete any existing rules before you add the new
ones:

With ActiveSheet.Range("C2:C11").Validation
.Delete
....rest of code

JMay wrote:

On page 189 of Excel 2003 Programming - Inside/Out an
Example is given to set Validation criteria for 10 cells in Column C

Before Entering anything into cells C2:C11 I created (in a std module):

Sub Tester()
With ActiveSheet.Range("C2:C11").Validation
.Add Type:=xlValidateWholeNumber, AlertStyle:=xlValidAlertStop, _
Operator:=xlLessEqual, Formula1:="5000"
.InputTitle = "Credit Limit"
.ErrorTitle = "Credit Limit too High"
.InputMessage = "Enter the Customer's Credit Limit."
.ErrorMessage = "The Credit limit must be less than $5,000."
End With
End Sub

Stepping thru the code I get a R/T error 1004;
Can anyone assist me in determining why?

There doesn't seem to be any errata available for this book.

TIA,

Jim May


--

Dave Peterson



JMay

Trying to demo Code, but get error
 
Never mind; I did the Edit Goto, Special..
To see that it is all there
Thanks Again,
Jim

"JMay" wrote in message
:

Thanks Guys and A Happy New Year to 'ya
Obviously, I was running more than Once;
The .Delete remedied it

Is there a way I can (In the Immediate window)
Determine the current Validation range (C2:C11)
Like:
? ValidationRange.Address
C2:C11 <<Results

Thanks,

Jim May


" wrote in message
:

If I ran it a second time, I got an error -- it's trying to add validation rules
to a range that already has rules.

But you could add a line to delete any existing rules before you add the new
ones:

With ActiveSheet.Range("C2:C11").Validation
.Delete
....rest of code

JMay wrote:

On page 189 of Excel 2003 Programming - Inside/Out an
Example is given to set Validation criteria for 10 cells in Column C

Before Entering anything into cells C2:C11 I created (in a std module):

Sub Tester()
With ActiveSheet.Range("C2:C11").Validation
.Add Type:=xlValidateWholeNumber, AlertStyle:=xlValidAlertStop, _
Operator:=xlLessEqual, Formula1:="5000"
.InputTitle = "Credit Limit"
.ErrorTitle = "Credit Limit too High"
.InputMessage = "Enter the Customer's Credit Limit."
.ErrorMessage = "The Credit limit must be less than $5,000."
End With
End Sub

Stepping thru the code I get a R/T error 1004;
Can anyone assist me in determining why?

There doesn't seem to be any errata available for this book.

TIA,

Jim May


--

Dave Peterson




All times are GMT +1. The time now is 11:15 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com