Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 101
Default Problems entering Data validation Programatically

I have one code that uses the change event to add validation boxes to any row
that doesn't have them.

I have another code to insert a special row, that has special validation
boxes(apart from the change event). My change event has a variable that stops
the change event from running while it's in process.

The problem is that when I activate the cahnge event, the validation runs
smoothly and is inserted into the sheet, using named ranges from another
sheet as the values for the drop down box. When I try to insert the special
row, and I use the exact same code to add the validation, it errors on the
add line:

With ActiveSheet.Range(Cells(iRow, iColumn).Address).Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=sRange

As you can see, I delete the current validation so that I can always use an
add routine. When I set a watch VBA sees the validation, but won't run the
line. I have tried removing all variables and tired not referring to a anmed
range and still get the error. I am using Excel 2000. Any ideas on why the
code will work in one procedure but not in another?

*********************
J Streger
MS Office Master 2000 ed.
MS Project White Belt 2003

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default Problems entering Data validation Programatically

Are you using Protection on your sheets? sometimes, I have found it is a
simple as having not unlocked the sheet - or having locked it from a
different section of code - particularly when it works sometimes and not
others.

another possibility could be using ActiveSheet within the code, maybe the
activesheet isn't the one you think it is, are other procedures activating
other sheets? - can you refer to the specific sheet name?

"J Streger" wrote:

I have one code that uses the change event to add validation boxes to any row
that doesn't have them.

I have another code to insert a special row, that has special validation
boxes(apart from the change event). My change event has a variable that stops
the change event from running while it's in process.

The problem is that when I activate the cahnge event, the validation runs
smoothly and is inserted into the sheet, using named ranges from another
sheet as the values for the drop down box. When I try to insert the special
row, and I use the exact same code to add the validation, it errors on the
add line:

With ActiveSheet.Range(Cells(iRow, iColumn).Address).Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=sRange

As you can see, I delete the current validation so that I can always use an
add routine. When I set a watch VBA sees the validation, but won't run the
line. I have tried removing all variables and tired not referring to a anmed
range and still get the error. I am using Excel 2000. Any ideas on why the
code will work in one procedure but not in another?

*********************
J Streger
MS Office Master 2000 ed.
MS Project White Belt 2003

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 101
Default Problems entering Data validation Programatically

I was using active sheet, but after removing the instances of that, the error
still occurs. Here is the subroutine I'm using to add validation. It works in
one line of code and not the other. The break occurs at the .add line:

Private Sub Add_Validation(ByVal iRow As Integer, ByVal iColumn As Integer, _
ByVal sRange As String, ByVal oSheet As
Worksheet, Optional sInputTitle As String, _
Optional sInputMessage As String, Optional
sErrorTitle As String, _
Optional sErrorMessage As String)

Dim bShowInput As Boolean
Dim bShowError As Boolean

If IsMissing(sInputTitle) And IsMissing(sInputMessage) Then
bShowInput = False
Else
bShowInput = True
End If
If IsMissing(sErrorTitle) And IsMissing(sErrorMessage) Then
bShowError = False
Else
bShowError = True
End If
If IsMissing(sInputTitle) Then sInputTitle = ""
If IsMissing(sInputMessage) Then sInputMessage = ""
If IsMissing(sErrorTitle) Then sErrorTitle = ""
If IsMissing(sErrorMessage) Then sErrorMessage = ""

sRange = "=" & sRange

With oSheet.Range(Cells(iRow, iColumn).Address).Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=sRange
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = sInputTitle
.ErrorTitle = sErrorTitle
.InputMessage = sInputMessage
.ErrorMessage = sErrorMessage
.ShowInput = bShowInput
.ShowError = bShowError
End With



End Sub

"Simon Shaw" wrote:

Are you using Protection on your sheets? sometimes, I have found it is a
simple as having not unlocked the sheet - or having locked it from a
different section of code - particularly when it works sometimes and not
others.

another possibility could be using ActiveSheet within the code, maybe the
activesheet isn't the one you think it is, are other procedures activating
other sheets? - can you refer to the specific sheet name?

"J Streger" wrote:

I have one code that uses the change event to add validation boxes to any row
that doesn't have them.

I have another code to insert a special row, that has special validation
boxes(apart from the change event). My change event has a variable that stops
the change event from running while it's in process.

The problem is that when I activate the cahnge event, the validation runs
smoothly and is inserted into the sheet, using named ranges from another
sheet as the values for the drop down box. When I try to insert the special
row, and I use the exact same code to add the validation, it errors on the
add line:

With ActiveSheet.Range(Cells(iRow, iColumn).Address).Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=sRange

As you can see, I delete the current validation so that I can always use an
add routine. When I set a watch VBA sees the validation, but won't run the
line. I have tried removing all variables and tired not referring to a anmed
range and still get the error. I am using Excel 2000. Any ideas on why the
code will work in one procedure but not in another?

*********************
J Streger
MS Office Master 2000 ed.
MS Project White Belt 2003

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 101
Default Problems entering Data validation Programatically

After lots of trial and error I found that the validation error was fixed
merely by activating the cell that I wanted to add validating to before
adding it. I even activated a cell in the same row and it worked. Thanks for
your help.

"Simon Shaw" wrote:

Are you using Protection on your sheets? sometimes, I have found it is a
simple as having not unlocked the sheet - or having locked it from a
different section of code - particularly when it works sometimes and not
others.

another possibility could be using ActiveSheet within the code, maybe the
activesheet isn't the one you think it is, are other procedures activating
other sheets? - can you refer to the specific sheet name?

"J Streger" wrote:

I have one code that uses the change event to add validation boxes to any row
that doesn't have them.

I have another code to insert a special row, that has special validation
boxes(apart from the change event). My change event has a variable that stops
the change event from running while it's in process.

The problem is that when I activate the cahnge event, the validation runs
smoothly and is inserted into the sheet, using named ranges from another
sheet as the values for the drop down box. When I try to insert the special
row, and I use the exact same code to add the validation, it errors on the
add line:

With ActiveSheet.Range(Cells(iRow, iColumn).Address).Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=sRange

As you can see, I delete the current validation so that I can always use an
add routine. When I set a watch VBA sees the validation, but won't run the
line. I have tried removing all variables and tired not referring to a anmed
range and still get the error. I am using Excel 2000. Any ideas on why the
code will work in one procedure but not in another?

*********************
J Streger
MS Office Master 2000 ed.
MS Project White Belt 2003

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems entering data in exel spreadsheet OneNightWithTheKing Excel Worksheet Functions 3 February 19th 10 09:44 PM
Data validation causing problems when using a data form in Excel 2 Peter Excel Worksheet Functions 1 November 27th 09 12:00 AM
Data validation problems changetires Excel Worksheet Functions 0 August 16th 06 02:30 AM
Data Validation lists - entering value not in list rgarber50 Excel Discussion (Misc queries) 3 July 19th 05 08:35 PM
Programatically Entering an Array Formula John C.[_4_] Excel Programming 1 July 28th 04 01:53 AM


All times are GMT +1. The time now is 02:26 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"