+ Reply to Thread
Results 1 to 6 of 6

VBA to set date range?

  1. #1
    Registered User
    Join Date
    06-18-2019
    Location
    Dallas, Texas
    MS-Off Ver
    windows 2013
    Posts
    72

    VBA to set date range?

    Hello all,

    I am using a current macro that pulls from a column of set range of dates. Is there a way to set a standard date so 2019 dates will show up 1/1/2019-12/31/2018 same with 2020 and so on filling in. I do not know if this is in excel settings or something I will have to call in vba.

    Thanks
    Attached Files Attached Files
    Last edited by Tgbell; 07-10-2019 at 10:59 AM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: VBA to set date range?

    Please upload a workbook or a representative cut down copy, anonymised if necessary. It is always easier to advise if we can see your request in its context.

    Show a before and after situation with manually calculated results, explaining which information is data and which is results, and if it's not blindingly obvious how you have arrived at your results some explanatory notes as well.

    To upload a file click the Go Advanced button at the foot of your post, look underneath the post area for the Manage Attachments section and take it from there.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    06-18-2019
    Location
    Dallas, Texas
    MS-Off Ver
    windows 2013
    Posts
    72

    Re: VBA to set date range?

    I just added it above, to reiterate to hopefully explain better: I am using
    Please Login or Register  to view this content.
    which I have number formatted to show year, however it shows from today so 7/10/2019-7/10/2020 ( a year after current day). This messes up the pull from the function because it is supposed to be pulling all 2019 dates (1/1/2019-12/31/2019), the code shows more, I did not know how to really add the after besides explaing it. The after should just show the correct date range in year.

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: VBA to set date range?

    Sorry but I find the explanation confusing.

    Remember you are intimately au fait with your data and terminology, know what it is and know what results it should give and where.
    We don't. We start from zero knowledge of your system and requirement so you need to be absolutely precise and explain in detail making reference to specific cells all the time.

    You should show exactly what you start with, and manually add in another area exactly what you want to see after any formulae or actions have been applied. Explain step by step how you use this workbook.

  5. #5
    Registered User
    Join Date
    06-18-2019
    Location
    Dallas, Texas
    MS-Off Ver
    windows 2013
    Posts
    72

    Re: VBA to set date range?

    Rich,
    The process goes like this: I copy each day's data and paste on Sheet2, I then run my macro with the formulas you can see, and it calculates min,max, so on (on notes page). These formulas reference the dates on Sheet 2 (column E and G), and compare them with the dates in column A on Notes. By comparing them, it is putting in information and calculating by separating the items on Sheet 2 by company and year. The data validation table (on the right of Notes gives the option to select one company or a few. When my formulas CURRENTLY reference the date (which is in years) it refers to 7/10/2019-7/10/2020 which is from column A. When I run the current macro, some dates for 2020 show up in 2019 since it is a messed up date range.

    Since on sheet2 the dates could be totally random within a year, I need my code in Column A to have a standard year, by formula, so 1/1/2019-12/31/2019 and fill down. This will now sort my data correctly when my macro runs.

    The finished product should pull the correct years for the company because the years will be the entire year, not today and a year from today.

  6. #6
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,535

    Re: VBA to set date range?

    If you only want to pull data between January 1st and December 31st of a given year then you could modify the formula for "MIN" (Cell B3) so that it reads:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Let us know if you have any questions.
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 4
    Last Post: 03-21-2018, 09:25 AM
  2. Highlight a date range if today's date falls within that range
    By sdarnell in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-01-2014, 10:03 AM
  3. VBA to enter date range based on date range in above cell
    By Pierce Quality in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-19-2013, 08:45 AM
  4. Search date range +/- 7 days and return date that falls within range
    By tlafferty in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 07-13-2013, 03:26 PM
  5. Replies: 9
    Last Post: 06-21-2012, 03:46 PM
  6. [SOLVED] Calculate how many days in one date range fall into a second date range
    By globalpontoon in forum Excel General
    Replies: 2
    Last Post: 05-08-2012, 03:02 PM
  7. Replies: 4
    Last Post: 03-18-2011, 07:02 AM

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