+ Reply to Thread
Results 1 to 7 of 7

How to change cell colour based on numer of months?

  1. #1
    Tiago
    Guest

    How to change cell colour based on numer of months?

    Hello all,

    I need a function that have an initial date on a cell (ex: 25-05-2005) and
    returns one year next to that date (ex:25-05-2006), and this is ok.

    To this date that i have(25-05-2006) i need to count the number of months
    that passed until now(in this case is 0 months) and if the month is 0 to 10,
    fill in the current row the (25-05-2006) cell to red. If is in 11 to 12 fill
    it in green. and if is it higher than 12, fill in yellow

    my problem is, that the excelsheet does', select any cell and don't fill
    anything

    can you help me?
    Thank You

    PS: i'm trying in that way

    Public Function give_date(initialdate, line)
    ......

    Select Case numerofmonths
    Case Is <= 10
    Range("G" + Trim(Str(line))).Select
    With Selection.Interior
    .ColorIndex = 3
    .Pattern = xlSolid
    End With
    Case 11 To 15
    Range("G" + Trim(Str(line))).Select
    With Selection.Interior
    .ColorIndex = 46
    .Pattern = xlSolid
    End With

    Case Is > 15
    Range("G" + Trim(Str(line))).Select
    With Selection.Interior
    .ColorIndex = 10
    .Pattern = xlSolid
    End With

    End Select

    give_date = nextdate

    End Function

  2. #2
    Ivan Raiminius
    Guest

    Re: How to change cell colour based on numer of months?

    Hi,

    can't you use conditional formatting?

    Regards,
    Ivan


  3. #3
    Tiago
    Guest

    Re: How to change cell colour based on numer of months?

    and put what?


    "Ivan Raiminius" wrote:

    > Hi,
    >
    > can't you use conditional formatting?
    >
    > Regards,
    > Ivan
    >
    >


  4. #4
    Ivan Raiminius
    Guest

    Re: How to change cell colour based on numer of months?

    Hi,

    formula like:

    =datedif(date_you_have,now(),"m")<=10

    and the others two (believe you can write them yourself)

    date_you_have must be earlier then now.

    Regards,
    Ivan


  5. #5
    Bob Phillips
    Guest

    Re: How to change cell colour based on numer of months?

    Time for some research. Check out See
    http://www.contextures.com/xlCondFormat01.html

    --
    HTH

    Bob Phillips

    (remove xxx from email address if mailing direct)

    "Tiago" <[email protected]> wrote in message
    news:[email protected]...
    > and put what?
    >
    >
    > "Ivan Raiminius" wrote:
    >
    > > Hi,
    > >
    > > can't you use conditional formatting?
    > >
    > > Regards,
    > > Ivan
    > >
    > >




  6. #6
    Tiago
    Guest

    Re: How to change cell colour based on numer of months?

    it's an ideia,

    but it's better on a function, my big question, is why in the function, the
    color of worksheet doesn't change.

    i want to change the color tab too, and in conditional formating i can't

    thnks ivan


    "Ivan Raiminius" wrote:

    > Hi,
    >
    > formula like:
    >
    > =datedif(date_you_have,now(),"m")<=10
    >
    > and the others two (believe you can write them yourself)
    >
    > date_you_have must be earlier then now.
    >
    > Regards,
    > Ivan
    >
    >


  7. #7
    Ivan Raiminius
    Guest

    Re: How to change cell colour based on numer of months?

    Hi Tiago,

    it is not possible to change color of a cell via function (why is it
    better with function?). Use sub instead. Best solution is probably
    conditional formatting.

    Right, you cannot change tab color using conditional formatting. You
    can use statement like this:
    worksheets("somesheet").Tab.ColorIndex = some_number_(vba_constants)

    Regards,
    Ivan


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1