Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Why doesn't my loop work?

Can any one help me with this loop. I'm trying to set the validations for a
range of cell over all the worksheets in my workbook, but for some reason it
will only change the validations for the active sheet. If I change the code
to something simple like "MsgBox wsheet.Name" it cycles through all the
sheets. The main part of the code was copied from a recorded macro and added
to the loop code.

Here is the code:

Sub Set_Validation_Use_By_Date()
Dim wsheet As Worksheet
For Each wsheet In ActiveWorkbook.Worksheets
Range("L10:L169").Select
With Selection.Validation
.Delete
.Add Type:=xlValidateDate, AlertStyle:=xlValidAlertStop, Operator:=
_
xlGreater, Formula1:="=TODAY()"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = "Date Error"
.InputMessage = ""
.ErrorMessage = _
"The date you have entered is in the past. Please check the date and
enter again."
.ShowInput = True
.ShowError = True
End With
Next
End Sub

Any ideas would be greatly appreciated.

Insp Gadget




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Why doesn't my loop work?

You can't select a range on an inactive sheet and in fact, there is no need
to select it.

For Each wsheet In ActiveWorkbook.Worksheets
wsheet.Range("L10:L169").Validation
.Delete
'etc.

--

Vasant


"Insp Gadget " <oakeypara<<REMOVE wrote in message
...
Can any one help me with this loop. I'm trying to set the validations for

a
range of cell over all the worksheets in my workbook, but for some reason

it
will only change the validations for the active sheet. If I change the

code
to something simple like "MsgBox wsheet.Name" it cycles through all the
sheets. The main part of the code was copied from a recorded macro and

added
to the loop code.

Here is the code:

Sub Set_Validation_Use_By_Date()
Dim wsheet As Worksheet
For Each wsheet In ActiveWorkbook.Worksheets
Range("L10:L169").Select
With Selection.Validation
.Delete
.Add Type:=xlValidateDate, AlertStyle:=xlValidAlertStop,

Operator:=
_
xlGreater, Formula1:="=TODAY()"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = "Date Error"
.InputMessage = ""
.ErrorMessage = _
"The date you have entered is in the past. Please check the date

and
enter again."
.ShowInput = True
.ShowError = True
End With
Next
End Sub

Any ideas would be greatly appreciated.

Insp Gadget






  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Why doesn't my loop work?

Sorry, forgot the "With" in the second line.


"Vasant Nanavati" <vasantn *AT* aol *DOT* com wrote in message
...
You can't select a range on an inactive sheet and in fact, there is no

need
to select it.

For Each wsheet In ActiveWorkbook.Worksheets
wsheet.Range("L10:L169").Validation
.Delete
'etc.

--

Vasant


"Insp Gadget " <oakeypara<<REMOVE wrote in message
...
Can any one help me with this loop. I'm trying to set the validations

for
a
range of cell over all the worksheets in my workbook, but for some

reason
it
will only change the validations for the active sheet. If I change the

code
to something simple like "MsgBox wsheet.Name" it cycles through all the
sheets. The main part of the code was copied from a recorded macro and

added
to the loop code.

Here is the code:

Sub Set_Validation_Use_By_Date()
Dim wsheet As Worksheet
For Each wsheet In ActiveWorkbook.Worksheets
Range("L10:L169").Select
With Selection.Validation
.Delete
.Add Type:=xlValidateDate, AlertStyle:=xlValidAlertStop,

Operator:=
_
xlGreater, Formula1:="=TODAY()"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = "Date Error"
.InputMessage = ""
.ErrorMessage = _
"The date you have entered is in the past. Please check the date

and
enter again."
.ShowInput = True
.ShowError = True
End With
Next
End Sub

Any ideas would be greatly appreciated.

Insp Gadget








  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Why doesn't my loop work?

I changed it slightly it should work now, try not to use "selection" if at
all possible it slows things down to much and causes unnecessary errors.

Sub Set_Validation_Use_By_Date()
Dim wsheet As Worksheet
For Each wsheet In ActiveWorkbook.Worksheets

With Range("L10:L169").Validation
.Delete
.Add Type:=xlValidateDate, AlertStyle:=xlValidAlertStop, Operator:=
_
xlGreater, Formula1:="=TODAY()"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = "Date Error"
.InputMessage = ""
.ErrorMessage = _
"The date you have entered is in the past. Please check the date and
enter again."
.ShowInput = True
.ShowError = True
End With
Next
End Sub

--
Regards,
Rocky McKinley


"Insp Gadget " <oakeypara<<REMOVE wrote in message
...
Can any one help me with this loop. I'm trying to set the validations for

a
range of cell over all the worksheets in my workbook, but for some reason

it
will only change the validations for the active sheet. If I change the

code
to something simple like "MsgBox wsheet.Name" it cycles through all the
sheets. The main part of the code was copied from a recorded macro and

added
to the loop code.

Here is the code:

Sub Set_Validation_Use_By_Date()
Dim wsheet As Worksheet
For Each wsheet In ActiveWorkbook.Worksheets
Range("L10:L169").Select
With Selection.Validation
.Delete
.Add Type:=xlValidateDate, AlertStyle:=xlValidAlertStop,

Operator:=
_
xlGreater, Formula1:="=TODAY()"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = "Date Error"
.InputMessage = ""
.ErrorMessage = _
"The date you have entered is in the past. Please check the date

and
enter again."
.ShowInput = True
.ShowError = True
End With
Next
End Sub

Any ideas would be greatly appreciated.

Insp Gadget






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Why doesn't my loop work?

Excellent, thanks for the solution works like a charm. I've been trying to
sort this out for ages. Much appreciated!!


"Rocky McKinley" wrote in message
...
I changed it slightly it should work now, try not to use "selection" if at
all possible it slows things down to much and causes unnecessary errors.

Sub Set_Validation_Use_By_Date()
Dim wsheet As Worksheet
For Each wsheet In ActiveWorkbook.Worksheets

With Range("L10:L169").Validation
.Delete
.Add Type:=xlValidateDate, AlertStyle:=xlValidAlertStop,

Operator:=
_
xlGreater, Formula1:="=TODAY()"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = "Date Error"
.InputMessage = ""
.ErrorMessage = _
"The date you have entered is in the past. Please check the date

and
enter again."
.ShowInput = True
.ShowError = True
End With
Next
End Sub

--
Regards,
Rocky McKinley


"Insp Gadget " <oakeypara<<REMOVE wrote in message
...
Can any one help me with this loop. I'm trying to set the validations

for
a
range of cell over all the worksheets in my workbook, but for some

reason
it
will only change the validations for the active sheet. If I change the

code
to something simple like "MsgBox wsheet.Name" it cycles through all the
sheets. The main part of the code was copied from a recorded macro and

added
to the loop code.

Here is the code:

Sub Set_Validation_Use_By_Date()
Dim wsheet As Worksheet
For Each wsheet In ActiveWorkbook.Worksheets
Range("L10:L169").Select
With Selection.Validation
.Delete
.Add Type:=xlValidateDate, AlertStyle:=xlValidAlertStop,

Operator:=
_
xlGreater, Formula1:="=TODAY()"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = "Date Error"
.InputMessage = ""
.ErrorMessage = _
"The date you have entered is in the past. Please check the date

and
enter again."
.ShowInput = True
.ShowError = True
End With
Next
End Sub

Any ideas would be greatly appreciated.

Insp Gadget










  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Why doesn't my loop work?

Instead of:
Range("L10:L169").Select
With Selection.Validation

Try:
With wsheet.Range("L10:L169").Validation


"Insp Gadget " <oakeypara<<REMOVE wrote in message
...
Can any one help me with this loop. I'm trying to set the validations for

a
range of cell over all the worksheets in my workbook, but for some reason

it
will only change the validations for the active sheet. If I change the

code
to something simple like "MsgBox wsheet.Name" it cycles through all the
sheets. The main part of the code was copied from a recorded macro and

added
to the loop code.

Here is the code:

Sub Set_Validation_Use_By_Date()
Dim wsheet As Worksheet
For Each wsheet In ActiveWorkbook.Worksheets
Range("L10:L169").Select
With Selection.Validation
.Delete
.Add Type:=xlValidateDate, AlertStyle:=xlValidAlertStop,

Operator:=
_
xlGreater, Formula1:="=TODAY()"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = "Date Error"
.InputMessage = ""
.ErrorMessage = _
"The date you have entered is in the past. Please check the date

and
enter again."
.ShowInput = True
.ShowError = True
End With
Next
End Sub

Any ideas would be greatly appreciated.

Insp Gadget






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
how can i automatically generate work order numbers from work orde rob h Excel Discussion (Misc queries) 1 July 13th 09 07:59 PM
flash object dont work in my excel work sheet Nitn Excel Discussion (Misc queries) 0 July 4th 09 08:00 AM
Find loop doesn't loop JSnow Excel Discussion (Misc queries) 2 June 24th 09 08:28 PM
Is there away to keep "auto save" from jumping to the first work sheet in the work book? Marc New Users to Excel 2 April 21st 05 01:27 AM
HELP!!!! Can't stop a loop (NOT an infinite loop) TBA[_2_] Excel Programming 3 December 14th 03 03:33 PM


All times are GMT +1. The time now is 06:29 PM.

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

About Us

"It's about Microsoft Excel"