+ Reply to Thread
Results 1 to 6 of 6

Custom function - Help please

  1. #1

    Custom function - Help please

    Hello,

    I created this function but I don't know why it doesn't work properly.
    Any help appreciate.
    Thank you.

    Regards,
    Thierry

    Function Tps(Livrele As Range, Requispour As Range)
    Dim Delay As Integer
    Delay = Range(Requispour).Value - Range(Livrele).Value
    If Delay < 0 Then
    Range(Requispour.Column + 1).Interior.ColorIndex = 55
    Range(Requispour.Column + 1).Font.ColorIndex = 0
    Else
    Range(Requispour.Column + 1).Interior.ColorIndex = 0
    Range(Requispour.Column + 1).Font.ColorIndex = 1
    End If
    End Function


  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello mrjaune,

    Change your code to this...

    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

  3. #3
    Alvin
    Guest

    RE: Custom function - Help please

    you didn't specify the row reference.
    Range(Requispour.Column + 1).Interior.ColorIndex = 55

    try:
    Requispour.Offset(0,1).Interior.ColorIndex = 55

    "[email protected]" wrote:

    > Hello,
    >
    > I created this function but I don't know why it doesn't work properly.
    > Any help appreciate.
    > Thank you.
    >
    > Regards,
    > Thierry
    >
    > Function Tps(Livrele As Range, Requispour As Range)
    > Dim Delay As Integer
    > Delay = Range(Requispour).Value - Range(Livrele).Value
    > If Delay < 0 Then
    > Range(Requispour.Column + 1).Interior.ColorIndex = 55
    > Range(Requispour.Column + 1).Font.ColorIndex = 0
    > Else
    > Range(Requispour.Column + 1).Interior.ColorIndex = 0
    > Range(Requispour.Column + 1).Font.ColorIndex = 1
    > End If
    > End Function
    >
    >


  4. #4
    Norman Jones
    Guest

    Re: Custom function - Help please

    Hi Thierry,

    Firstly, change:

    > Delay = Range(Requispour).Value - Range(Livrele).Value

    to:
    Delay = Requispour.Value - Livrele.Value

    You have already declared Requispour and Livrele as ranges.

    It is not clear to me what range you are attempting to define in the
    expression:

    > Range(Requispour.Column + 1)


    Perhaps you could describe the range in words?

    It should also be noted that, if you intend to use your function as a
    worksheet function (UDF), the UDF cannot change the format of cells other
    than the calling cell.

    ---
    Regards,
    Norman



    <[email protected]> wrote in message
    news:[email protected]...
    > Hello,
    >
    > I created this function but I don't know why it doesn't work properly.
    > Any help appreciate.
    > Thank you.
    >
    > Regards,
    > Thierry
    >
    > Function Tps(Livrele As Range, Requispour As Range)
    > Dim Delay As Integer
    > Delay = Range(Requispour).Value - Range(Livrele).Value
    > If Delay < 0 Then
    > Range(Requispour.Column + 1).Interior.ColorIndex = 55
    > Range(Requispour.Column + 1).Font.ColorIndex = 0
    > Else
    > Range(Requispour.Column + 1).Interior.ColorIndex = 0
    > Range(Requispour.Column + 1).Font.ColorIndex = 1
    > End If
    > End Function
    >




  5. #5

    Re: Custom function - Help please

    Hi Norman,
    And thanks for your help.

    I want do for example:
    Delay = cell H11 - cell F11
    and if the result is negative (the result is in cell J11)
    I want the cell J11 fill in orange and the result in white.
    Otherwise, if the result is positive I want no fill and text in black.
    And next I can copy my Tps function to a J12:J650 range.

    I can't use a conditional formating because I can't copy the formula to
    a range.
    I tried it before.

    In my mind I want write this formula in cell J11: =Tps(F11,H11)

    Regards,
    Thierry


  6. #6
    Norman Jones
    Guest

    Re: Custom function - Help please

    Hi Thierry,

    > I can't use a conditional formating because I can't copy the formula to
    > a range.
    > I tried it before.


    Select cells J11:J650
    Format | Conditional Formatting
    Formula Is =$H11-$F11<0 Fill color: Orange, Font color: White

    worked for me.

    ---
    Regards,
    Norman



    <[email protected]> wrote in message
    news:[email protected]...
    > Hi Norman,
    > And thanks for your help.
    >
    > I want do for example:
    > Delay = cell H11 - cell F11
    > and if the result is negative (the result is in cell J11)
    > I want the cell J11 fill in orange and the result in white.
    > Otherwise, if the result is positive I want no fill and text in black.
    > And next I can copy my Tps function to a J12:J650 range.
    >
    > I can't use a conditional formating because I can't copy the formula to
    > a range.
    > I tried it before.
    >
    > In my mind I want write this formula in cell J11: =Tps(F11,H11)
    >
    > Regards,
    > Thierry
    >




+ 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