+ Reply to Thread
Results 1 to 5 of 5

Lots of IFs based on User-inputted date

  1. #1
    Registered User
    Join Date
    11-29-2010
    Location
    NYC
    MS-Off Ver
    Excel 2003
    Posts
    11

    Lots of IFs based on User-inputted date

    Hello everyone,

    This is a tricky one, any advice is appreciated here.

    I need the user to input a date into my Excel Macro through a popup (InputBox)

    Using that input (We'll call it MailerDate) we need to:

    For each row...

    Compare the input (MailerDate) to the date in column T ('Contract End') [Format: DD/MM/YY)]


    If the date is anything up to 1 Month minus 1 day *after* MailerDate, the V column (of that row) needs to be changed to 0.

    If the date in column T is 1 month after MailerDate TO 2 months minus 1 day after MailerDate, value of the V needs to be changed to 1.

    If the date in column T is 2 months after MailerDate TO 3 months minus 1 day after MailerDate, value of the V needs to be changed to 2.

    and so on until..

    If the date in column T is 18 months after the MailerDate to 19 months minus 1 day after the MailerDate, value of the V needs to be changed to 18.


    It's a complicated one - but it's basically a IF statement (or CASE? Not that familiar with the VBScripting) and a InputBox used to input a date.. With a loop to run this to the last row of the excel file.

    Suggestions?

    So far all I have is..

    MailerDate = InputBox("Enter the mailing date - Format MM/DD", "Enter Mailing Date", "MM/DD")

    Dim r As Range, i As Long

    For Each r In Range("V2", Range("V2").End(xlDown))
    If
    {still researching how to do this exactly..}
    End If
    Next r
    Thanks so much!

    Daniel
    Last edited by lieb39; 11-29-2010 at 04:15 PM.

  2. #2
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Lots of IFs based on User-inputted date

    Want to get your question answered quickly?
    ...

    Post a WORKBOOK. Nobody wants to type data from a picture or paste text from your post into a spreadsheet as a prelude to helping. To attach a file, push the button with the paperclip (or scroll down to the Manage Attachments button), browse to the required file, and then push the Upload button.

    If your question has not been answered within a day, consider adding another post with any additional information you believe is relevant. If you think your post is good as is, just reply to your own thread with the words "Bump no response", which will bring it to the top of the forum.

  3. #3
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Lots of IFs based on User-inputted date

    assuming that the dates in column T are Excel serial dates.
    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  4. #4
    Registered User
    Join Date
    11-29-2010
    Location
    NYC
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Lots of IFs based on User-inputted date

    Hello,

    Okay, I have created a formula.. but it's messy. And it doesn't actually do exactly what I like. Instead, it increments when 1 month days have increased, as opposed to 1 month - 1 day.

    If anyone can come up with the code for a macro, feel free. Otherwise I guess I'll just have to use the formula..

    Cheers,
    Daniel.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    11-29-2010
    Location
    NYC
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Lots of IFs based on User-inputted date

    Trying to implement this into my Macro..

    I have the following code that results in a Run-Time error '1004'
    Method 'Formula' of object 'Range' failed

    MailerDate = InputBox("Enter the mailing date - Format DD/MM/YY - Example: 12/02/10", "Enter Mailing Date", "DD/MM/YY")
    Range("V2:V" & Range("A" & Rows.Count).End(xlUp).Row).Formula = "=IF(ISERROR(DATEDIF("& DateValue(MailerDate) &",RC[-2],'m')),0,DATEDIF(" & DateValue(MailerDate) & ",RC[-2],'m')"
    Any ideas why this is failing?

    Thanks,
    Daniel

+ 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