Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,073
Default Conditional formatting - different cell colour for each year following from user input date?

Hi Hypatia,
when I replaced that with "Wkt" just to see if it would work, it didn't.<


It does depend on the "Wkt#" and the reason it didn't work was you
probably kept the Number of Characters argument of the "Left" function
equal to 1, so, you have to change that line of code to :

If Left(SheetArray(iRowCounter, iColumnCounter), 3) = "Wkt" Then

for it to work. Notice the 3 ('Wkt" has 3 characters) where previously
there was a 1.

Correct if I'm wrong, if my memory serves me correct, you are not
wanting either the Wkt# or the series of underscores in the following
cell to appear in a new version for use at your workplace.
One way of achieving this is to include a line of code in that version
which makes the font color in those cells the same as the cell interior
color (icolor). This way they're still there, just not visible on
screen or printed page (I assume).

The new code follows:

Public Sub ColorYear()
Dim iRowCounter As Long, iColumnCounter As Long
Dim SheetArray As Variant
SheetArray = Range("A1:H1430")
For iRowCounter = 3 To UBound(SheetArray)
For iColumnCounter = 1 To UBound(SheetArray, 2)

If Left(SheetArray(iRowCounter, iColumnCounter), 1) = "W" Then
iYearIndex = Year(Cells(iRowCounter - 1, iColumnCounter +
1).Value) Mod 4
If iYearIndex = 0 Then Let icolor = 19 '2008,2012,2016
If iYearIndex = 1 Then Let icolor = 40 '2005,2009,2013
If iYearIndex = 2 Then Let icolor = 20 '2006,2010,2014
If iYearIndex = 3 Then Let icolor = 35 '2007,2011,2015

Range(Cells(iRowCounter - 2, iColumnCounter),
Cells(iRowCounter, iColumnCounter + 1)) _
.Interior.ColorIndex = icolor
Range(Cells(iRowCounter, iColumnCounter), Cells(iRowCounter,
iColumnCounter + 1)) _
.Font.ColorIndex = icolor
End If
Next iColumnCounter
Next iRowCounter

End Sub

If you run this code but then you change your mind because you want
them visible again you can change ".Font.ColorIndex = icolor" in the
last line of the loop to ".Font.ColorIndex = 0" then run the code
again.

Let me know how this goes.

Ken Johnson

Reply
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
Conditional formatting - getting input from another cell EricD Excel Worksheet Functions 6 October 1st 09 05:17 PM
Excel 2007 conditional formatting & cell colour. chris_g Excel Worksheet Functions 2 September 11th 08 05:20 PM
change tab colour when using conditional formatting in a cell julie s Excel Worksheet Functions 6 October 23rd 06 09:13 PM
How do I set up a cell to input a date 1 year from another cell? wyrmslair New Users to Excel 3 June 13th 06 09:21 PM
VBA: Look-Up Cell Date From User Input Box and return ALL matches Mcasteel[_38_] Excel Programming 1 November 11th 04 03:34 AM


All times are GMT +1. The time now is 12:29 AM.

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"