LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default On Error Resume Next question

My code is not acting as expected and I would appreciate some help in
understanding why. (I know very little about VBA programming, so
answers in the most basic terms would be helpful.)

My task is to go through each unlocked cell on a worksheet and set the
interior color based on the following criteria:

If there is data validation and the"Show error" box is checked, the
color should be light orange.
All other unlocked cells should be light yellow.

One of the problems I'm trying to work around is that if you test a
cell for Validation.ShowError and there is no data validation on the
cell, an error occurs. After reading other posts in this newsgroup, it
seems there is no simple way to test if data validation exists that
will generate a true/false answer, and the way around this is through
handling the error.

My code below attempts this. Every unlocked cell is turned yellow, and
then I tried to change only the ones with Validation.ShowError = True
to orange. Without the On Error Resume Next instruction, when the code
encounters a cell that is unlocked but does not have data validation,
I get an error at the second "if" clause. When I include the On Error
Resume Next statement, the code turns every cell unlocked cell to
orange, except for those where Validation.ShowError=False. (They stay
yellow.)

This is what I don't understand. Shouldn't the "next statement" after
the second If clause errors out be "End If"? It seems as if the line
that turns the color to orange is being treated like the next
statement, even though I think it's part of the If clause.

Any help or explanation would be appreciated.

The code starts he
~~~~~~~~~~~~~~

Dim urRows As Integer, urCols As Integer
Dim i As Integer, j As Integer

Worksheets("Sheet1").Activate
ActiveSheet.UsedRange.Select

urRows = Selection.Rows.Count
urCols = Selection.Columns.Count

ActiveSheet.UsedRange.Cells(1, 1).Select

For i = 1 To urRows
For j = 1 To urCols
On Error Resume Next
ActiveSheet.UsedRange.Cells(i, j).Select

If ActiveSheet.UsedRange.Cells(i, j).Locked = False Then
ActiveSheet.UsedRange.Cells(i, j).Interior.Color =
RGB(255, 255, 153) ' color = yellow
If ActiveSheet.UsedRange.Cells(i, j).Validation.ShowError
= True Then _
ActiveSheet.UsedRange.Cells(i, j).Interior.Color =
RGB(255, 204, 153) ' color = orange
End If
Next j
Next i
~~~~~~~~~~~
Thanks
Alice

 
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
on error resume next Janis Excel Programming 1 September 19th 06 08:12 PM
Resume on Error? dan Excel Programming 1 July 24th 06 06:53 PM
On Error {...} Resume Next Edd[_2_] Excel Programming 2 March 15th 06 11:09 PM
On error resume next? question - problem Andrzej Excel Programming 13 June 3rd 05 01:02 PM
"On Error Resume Next" Question Jim[_26_] Excel Programming 1 September 20th 03 07:38 PM


All times are GMT +1. The time now is 04:33 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"