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: 106
Default CODE given: Please help to rectify the error

Hello all,

I am trying to solve this situation by click event and NOT by
selectionchange event.. So, no target.value stuff. All I am trying to
do is pretty simple (but I face errors..). It is as follows. I have
given examples with the algorithm to ease reader's understanding
(hopefully)

In the range("A2:A6"), check the following for each cell.
1. If any cell has a colorindex = 3,4,or 6 then

2. Consider that cell's row.
For example, if A3 is a cell that has a colorindex of 3,4 or 6 then
consider B3 to IV3

3. In that row, if any cell has a numerical value, then highlight the
first cell of the corresponding column.
For example, in B3 to IV3, if E3, G3, J3 have a numerical value, then
highlight E1, G1, J1 with a colorindex 3.

4. Do the same for every cell in that range("A2:A6").

I have written the following code for this.. I face an error that says
that 'for' control is already in use. But, I cant think about modifying
the code without two 'for' statements.

Please provide your expertise to solve this problem.

Private Sub CommandButton1_Click()
For Each cell In Sheet1.Range("A2:A6")
If cell.Interior.ColorIndex = 3 Or cell.Interior.ColorIndex = 6 Or
cell.Interior.ColorIndex = 4 Then

Range("B1:IV1").Interior.ColorIndex = xlNone

Set rng = cell.Offset(0, 1).Resize(1, 255)
Set rng1 = Nothing
On Error Resume Next

Set rng1 = rng.SpecialCells(xlConstants)
On Error GoTo 0
If Not rng1 Is Nothing Then
For Each cell In rng1
If cell.Value < 0 Or cell.Value 0 Then
Sheet1.Cells(1, cell.Column).Interior.ColorIndex = 3
End If
Next
End If
End If
Next
End Sub

 
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
Rectify function - combination of Sumproduct and OR Hilton Excel Worksheet Functions 3 February 27th 08 01:46 PM
How rectify the DATA Error [47 OF 94 33 F4 55] Bhaskar Excel Discussion (Misc queries) 1 July 11th 07 04:20 PM
Protect Sheet with code, but then code will not Paste error. How do i get around this. Please read for explainations.... Corey Excel Programming 4 November 25th 06 04:57 AM
i cannot use the mouse right click in excel. how to rectify? j New Users to Excel 6 September 20th 06 01:54 PM
query wizard has stopped working how do i rectify this Marie LND Excel Worksheet Functions 0 February 18th 05 11:31 AM


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