PC Review


Reply
Thread Tools Rate Thread

Cells(row, j).Interior.colorindex

 
 
KT_1010
Guest
Posts: n/a
 
      5th Aug 2010
I wanted to set the color for a row to a specific value

for i = 1 to 30
Cells(ActiveCell.row, i).interior.colorindex = colIndex
next i

which should set the property for the first 30 cells of the current
row

The debugger aborts when it comes to this line, and I can't figure out
why

I've tried
myRow = ActiveCell.row (which should be the row
of the target cell)
With Worksheet("target").Cells(myRow, i)
.interior.colorindex = 33
.font.colorindex = 2
End with


which also doesn't work.
I had thought that Cells(i,j) assumed the current worksheet (and of
type Range)
(ActiveSheet.Cells(i,j) was a Range of one cell

also ActiveSheet.Rows(myRow).interior.colorindex also fails

how do I specify a range object that is the row that contains the
ActiveCell

(i've been trying to use the object browser to find a combination that
has the right syntax without much success.)
 
Reply With Quote
 
 
 
 
Jim Cone
Guest
Posts: n/a
 
      5th Aug 2010
Your first loop works for me in xl2003.
"Range(Cells(ActiveCell.Row, 1), Cells(ActiveCell.Row, 30)).Interior.ColorIndex = colIndex" also works.

How are i and colIndex declared?
What is the value of colIndex?
Is the sheet protected?
Is any part of the row merged?
--
Jim Cone
Portland, Oregon USA
Shade Data Rows add-in: http://tinyurl.com/ShadeData

..
..
..

"KT_1010" <(E-Mail Removed)>
wrote in message
I wanted to set the color for a row to a specific value

for i = 1 to 30
Cells(ActiveCell.row, i).interior.colorindex = colIndex
next i

which should set the property for the first 30 cells of the current row
The debugger aborts when it comes to this line, and I can't figure out why
I've tried
myRow = ActiveCell.row (which should be the row
of the target cell)
With Worksheet("target").Cells(myRow, i)
.interior.colorindex = 33
.font.colorindex = 2
End with

which also doesn't work.
I had thought that Cells(i,j) assumed the current worksheet (and of type Range)
(ActiveSheet.Cells(i,j) was a Range of one cell
also ActiveSheet.Rows(myRow).interior.colorindex also fails

how do I specify a range object that is the row that contains the ActiveCell
(i've been trying to use the object browser to find a combination that
has the right syntax without much success.)
 
Reply With Quote
 
KT_1010
Guest
Posts: n/a
 
      5th Aug 2010
Sub setHighlight(row As Long, cindex As Integer)
Dim ix As Long
Application.ScreenUpdating = False
For ix = 1 To 25
With Cells(row, ix)
.Font.ColorIndex = 2
.Interior.ColorIndex = cindex

End With
Next ix
Application.ScreenUpdating = True
End Sub

and call setHighlight(ActiveCell.Row, 23) ' 23 is one of the 56
possilble indexs to Colors
 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      5th Aug 2010
There's nothing obviously wrong with your routine.

FWIW no need to loop, eg

With Cells(row, 1).Resize(1, 25)
or
With Range(Cells(row, 1), Cells(row, 25))
.Font.ColorIndex = 2
.Interior.ColorIndex = cindex
End With

and if not looping no need to disable screenupdating just for that

Small thing, these days better to use As Long rather than As Integer, not
that it'll make any difference in your routine.

Regards,
Peter T

"KT_1010" <(E-Mail Removed)> wrote in message
news:f2ef15b2-5cbb-4b8d-975e-(E-Mail Removed)...
> Sub setHighlight(row As Long, cindex As Integer)
> Dim ix As Long
> Application.ScreenUpdating = False
> For ix = 1 To 25
> With Cells(row, ix)
> .Font.ColorIndex = 2
> .Interior.ColorIndex = cindex
>
> End With
> Next ix
> Application.ScreenUpdating = True
> End Sub
>
> and call setHighlight(ActiveCell.Row, 23) ' 23 is one of the 56
> possilble indexs to Colors


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Q: UDF with Interior.colorindex Help needed MAXX Microsoft Excel Programming 4 19th Jun 2011 12:14 PM
Select contiguous cells by ActiveCell.Interior.ColorIndex and applyborders nofam Microsoft Excel Programming 7 17th Mar 2010 08:50 AM
more on interior.colorindex issue bst Microsoft Excel Programming 4 2nd Jul 2008 05:43 PM
Use of Interior.ColorIndex liquidhot Microsoft Excel Programming 4 27th Jun 2005 07:22 PM
Testing for Interior.ColorIndex =?Utf-8?B?SmVmZkJv?= Microsoft Excel Programming 7 17th May 2004 09:41 PM


Features
 

Advertising
 

Newsgroups
 


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