New Excel Forum

This forum has been moved to TeachExcel.com

Ask all future questions in the New Excel Forum.

ExcelKey

how to shade a row of cells if 1 cell is odd or even

Macros, VBA, Excel Automation, etc.

how to shade a row of cells if 1 cell is odd or even

Postby GaryH » Wed Oct 21, 2015 5:34 pm

Hi
I am trying to shade a row of cells if the last cell is odd or even.
I have created the formula to give me an odd or even number in a hidden cell. I can use this and conditional formatting to shade that row ( shade = odd, leave = even ) BUT.. this information is then copied to 2 other spreadsheets but because of the conditional formatting the shade does not copy ( even if I use paste special - format ) here is an example.
I have used the 5th and 6th numbers in the first number (consignment) to create my odd or even number which sits in column L (hidden).

21100101 997 WED01 04:30
21100202 995 WED02 05:00
21100201 993 WED02 05:00
21100302 991 WED03 05:30
21100301 989 WED03 05:30
21100401 987 WED04 07:15
21100503 985 WED05 08:00
21100502 983 WED05 08:00
21100501 981 WED05 08:00

I already have a macro in use to merge the WED** column, Is there a way to add the shade to this macro ??

Thank you in advance...

Gary.


The merge macro I am using.........

Code: Select all
Sub merge()
    col = "J"
    lr = Cells(Rows.Count, col).End(xlUp).Row
    fr = 1
    tr = 1
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Do Until fr >= lr
        Do While Cells(tr + 1, col) = Cells(fr, col)
            tr = tr + 1
        Loop
        Range(Cells(fr, col), Cells(tr, col)).merge
        fr = tr + 1
        tr = fr
    Loop
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
End Sub
  • 0

Last edited by pecoflyer on Fri Oct 23, 2015 10:59 am, edited 1 time in total.
Reason: Added code tags
GaryH
Rookie
 
Posts: 1
Joined: Oct 21, 2015
Reputation: 0
Excel Version: 2007

Re: how to shade a row of cells if 1 cell is odd or even

Postby NoSparks » Wed Oct 21, 2015 9:10 pm

Merged cells are a cosmetic curse on Excel and should be avoided like the plague.

Try applying conditional formatting with a macro, something along the lines of this

Code: Select all
'range for conditional formatting
Set rng = Range("A5:S" & lastrow)
With rng
    'remove existing CF
    .Cells.FormatConditions.Delete
    'add conditional formatting
    .FormatConditions.Add Type:=xlExpression, Formula1:="=your formula in quotes"
    With .FormatConditions(1)
        .Interior.ColorIndex = 14   'grey
        .StopIfTrue = False
    End With
End With
  • 0

NoSparks
Excel Hobbyist
 
Posts: 637
Joined: May 28, 2014
Reputation: 103
Excel Version: 2010

Re: how to shade a row of cells if 1 cell is odd or even

Postby pecoflyer » Fri Oct 23, 2015 11:00 am

@GaryH
Hi and welcome. In the future please wrap code with code tags. Thx
  • 0

A relevant topic title helps get faster and more answers
pecoflyer
Moderator
 
Posts: 1274
Joined: Jan 24, 2012
Location: Belgium
Reputation: 39
Excel Version: 2003/2007/2010


Return to Macros and VBA Questions

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 224 guests