+ Reply to Thread
Results 1 to 5 of 5

Updating a cell based on contents of two other cells

  1. #1
    jonco
    Guest

    Updating a cell based on contents of two other cells

    I need a routine that will add so many days to another cell depending on the
    contents of a particular cell.
    I have a cell (J2) that has W (for weekly), B (for Bi Weekly), or M (for
    Monthly). When cell N2 (Last date) is updated with a new date, I need to
    add 7 days if J2 has a W, or 14 days if J2 has a B or 30 Days id J2 contains
    an M. and put the new date in cell L2 (the new due date),

    Cell L2 contains the Due Date.... the one that needs to be updated after the
    calculation
    Cell J2 contains the info to base the calculation on W, B, or M
    Cell N2 contains the old due date that is used to start the calculation

    Any help is greatly appreciated.

    Jonco



  2. #2
    Forum Expert Simon Lloyd's Avatar
    Join Date
    03-02-2004
    Location
    locked in the cage
    MS-Off Ver
    All the ones my homepage shows
    Posts
    3,161
    This should be what you need just paste it into the Sheet code module, I must tell you that the letter that appears in J2 must be upper case if you want it to be lower case just change it in the code, i'm sure someone will have a smarter way for you in this forum.

    Regards,
    Simon
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Range("J2").Text = "W" Then
    Range("L2") = Range("N2").Value + 7
    ElseIf Range("J2").Text = "B" Then
    Range("L2") = Range("N2").Value + 14
    ElseIf Range("J2").Text = "M" Then
    Range("L2") = Range("N2").Value + 30
    End If
    End Sub

  3. #3
    Ken Johnson
    Guest

    Re: Updating a cell based on contents of two other cells

    Hi jonco,

    Here's another way, but I don't know that it is smarter.

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$N$2" Or Target.Address = "$J$2" Then
    Dim iDays As Byte
    Application.EnableEvents = False
    On Error GoTo ERRORHANDLER
    Select Case UCase(Range("J2").Value)
    Case "W"
    iDays = 7
    Case "B"
    iDays = 14
    Case "M"
    iDays = 30
    End Select
    Range("L2").Value = Range("N2").Value + iDays
    Application.EnableEvents = True
    Exit Sub
    ERRORHANDLER:
    Application.EnableEvents = True
    End If
    End Sub

    Ken Johnson


  4. #4
    jonco
    Guest

    Re: Updating a cell based on contents of two other cells

    Thanks guys, I'll give these a try.

    Jonco


    "jonco" <jonco48@sbcglobal.net> wrote in message
    news:Oijqg.115855$H71.48310@newssvr13.news.prodigy.com...
    >I need a routine that will add so many days to another cell depending on
    >the contents of a particular cell.
    > I have a cell (J2) that has W (for weekly), B (for Bi Weekly), or M (for
    > Monthly). When cell N2 (Last date) is updated with a new date, I need
    > to add 7 days if J2 has a W, or 14 days if J2 has a B or 30 Days id J2
    > contains an M. and put the new date in cell L2 (the new due date),
    >
    > Cell L2 contains the Due Date.... the one that needs to be updated after
    > the calculation
    > Cell J2 contains the info to base the calculation on W, B, or M
    > Cell N2 contains the old due date that is used to start the calculation
    >
    > Any help is greatly appreciated.
    >
    > Jonco
    >




  5. #5
    Ken Johnson
    Guest

    Re: Updating a cell based on contents of two other cells


    You're welcome jonco, thanks for the feedback.

    Ken Johnson


+ 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