Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Meenachi Suppiah   on Dec 21 In MS Office Category.

  
Question Answered By: Shayan Anderson   on Dec 21

I wrote a bit of code  to strip every other row on a sheet. It takes
color of a cell  to get the color  index number. Here is my code. Maybe
it will give an idea.

Private Sub ColorAlternateRows()
'
Dim myColor As Integer
Dim myColorPattern As Integer
Dim myColorRange As Range
Dim cell As Range
Dim myRange As Range

'This code should only run on the "Status" sheet
If ActiveSheet.Name <> Sheet2.Name Then End

'Set the variable "myColorRange" equal to the named worksheet range
that will contain the color
Set myColorRange = Range("Color_For_Status_Rows")

'Now put the "myColor" variable equal to the color index number  of the
cell
myColor = myColorRange.Interior.ColorIndex

'as well as the cell's pattern into the variable "myColorPattern".
myColorPattern = myColorRange.Interior.Pattern

'This for loop then colors the rows in the list based on if their row
number is odd or even. Pick a light color for the fill.
For Each cell In Range([a50000].End(xlUp), [a12]) 'establish the
used range below cell A12
If cell.Offset(0, 1) <> "N" Then
If cell.Row Mod 2 Then
Set myRange = Range(cell, cell.Offset(0,
Range("Status_Sheet_Comments").Offset(0, 7).Column))
myRange.Interior.ColorIndex = myColor
myRange.Interior.Pattern = myColorPattern
With myRange.EntireRow.Borders(xlEdgeBottom)
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Else
Set myRange = Range(cell, cell.Offset(0,
Range("Status_Sheet_Comments").Offset(0, 7).Column))
myRange.Interior.ColorIndex = xlNone
myRange.Interior.Pattern = 1
With myRange.EntireRow.Borders(xlEdgeBottom)
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End If
End If
Next
End Sub

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on User Input Or get search suggestion and latest updates.


Tagged: