+ Reply to Thread
Results 1 to 12 of 12

VBA Find Specific Weeks of Data

  1. #1
    Valued Forum Contributor unit285's Avatar
    Join Date
    10-29-2015
    Location
    TN
    MS-Off Ver
    Office 365
    Posts
    358

    VBA Find Specific Weeks of Data

    Ok, Not sure how to even put my problem into writing but I will try.
    So I have a sheet of data that gets updated daily. Once a week I have a report that gets filled out from the data contained in the Database Sheet.
    The Report is comprised of 7 days worth of data beginning with Monday and ending with Sunday. Each Report is identified by the Week Ending Date. I need to be able to sort through all the data at anytime and generate these reports. I created a Userform which has a ComboBox with the Months listed, Beside that is a TextBox where the year can be entered. Once the Criteria is selected there is a second ComboBox which should have up to 5 options for that month. Each Option would be a Week Ending Report. What I tried was to create a named Range of the data by Month. If I could do that I could search for the First "Sunday" and then use .Offset to go from there. But I am not sure how to narrow down my named Range to be in the correct year and then in the correct Month. Please Help. Thanks!
    Attached Files Attached Files

  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 Find Specific Weeks of Data

    Hi,

    Sounds like a job for a Pivot Table rather than VBA.

    Here's an example which summarises data by weeks based on the year and month you pick in B1 & B2.

    Your data is clearly not representative of real data which if its numeric could just as easily be summed rather than counted.
    Attached Files Attached Files
    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
    Valued Forum Contributor unit285's Avatar
    Join Date
    10-29-2015
    Location
    TN
    MS-Off Ver
    Office 365
    Posts
    358

    Re: VBA Find Specific Weeks of Data

    I'm not familiar with Pivot Tables but I need it to work with vba for the simple reason the actual worksheet looks vastly different then the test sheet i attached. It uses close to 100 columns of data and has many other vba tools built in as well. I'm just looking for a method to then incorporate into my actual sheet. If I select February, 2016 I need my macro to find the first Sunday in the month of February in the Year of 2016 and assign it a variable. From there I am set and know how to proceed.

  4. #4
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: VBA Find Specific Weeks of Data

    This for the Button Generate Report
    With this code result go to Sheet Report if it is present in the workbook

    Please Login or Register  to view this content.
    Kind regards
    Leo

  5. #5
    Valued Forum Contributor unit285's Avatar
    Join Date
    10-29-2015
    Location
    TN
    MS-Off Ver
    Office 365
    Posts
    358

    Re: VBA Find Specific Weeks of Data

    Thanks for the replies so far, LeoTaxi I tried your code but it does not seem to be working, it copies 7 lines of data to the report Sheet but it is not the correct lines of data. When my userform has February, 2016 selected it copies this data to the Report Sheet. See Screenshot http://prntscr.com/d56ifo

  6. #6
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: VBA Find Specific Weeks of Data

    Strange, this is the result i get
    Attached Images Attached Images

  7. #7
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: VBA Find Specific Weeks of Data

    the file were i get good result




    Kind regards
    Leo
    Attached Files Attached Files

  8. #8
    Valued Forum Contributor unit285's Avatar
    Join Date
    10-29-2015
    Location
    TN
    MS-Off Ver
    Office 365
    Posts
    358

    Re: VBA Find Specific Weeks of Data

    Ok your file gives me a slightly different result.. I am a bit confused tho, the dates on the left indicate January, 2016 but the Month Column is saying February? I like the method. But it is giving me inaccurate results?
    Last edited by unit285; 11-09-2016 at 04:05 PM.

  9. #9
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: VBA Find Specific Weeks of Data

    result is February

    Comobox2 emty from 1 to 7
    Combobox2 with 1 from 8 to 14
    Combobox2 with 2 from 15 to 21
    Combobox2 with 3 from 22 to 28

    Cheers
    Leo

  10. #10
    Valued Forum Contributor unit285's Avatar
    Join Date
    10-29-2015
    Location
    TN
    MS-Off Ver
    Office 365
    Posts
    358

    Re: VBA Find Specific Weeks of Data

    Here is my test file and my steps have been to click commandbutton on Database Sheet which brings up the userform. I select February in CB1 and 2016 in TB1 and then hit Generate Report
    It is not working for some reason. I am sorry, I am not very experienced with vba. Thanks so much for you help
    Attached Files Attached Files

  11. #11
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: VBA Find Specific Weeks of Data

    Maybe it is the different beetween version 2007 en 2016
    i have good result with the last file as well

  12. #12
    Valued Forum Contributor unit285's Avatar
    Join Date
    10-29-2015
    Location
    TN
    MS-Off Ver
    Office 365
    Posts
    358

    Re: VBA Find Specific Weeks of Data

    I am using Office 2016..

+ 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. Calculate the first Saturday for a specific number of weeks after
    By mklindquist0815 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-05-2015, 09:16 PM
  2. Add value to specific number of weeks?
    By shiftyspina in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-04-2014, 08:55 AM
  3. [SOLVED] Find Day of week in Data table and chart 4 weeks
    By Grimace in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-05-2013, 02:13 AM
  4. populate a cell with a value based upon a specific time (weeks)
    By TMZSourcing in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 10-18-2013, 01:46 PM
  5. Replies: 2
    Last Post: 03-28-2013, 12:19 AM
  6. [SOLVED] Help with finding a specific day/date ten weeks away
    By yeahyeahyeah in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-25-2012, 06:12 PM
  7. Rename tabs in a template to specific weeks.
    By kAustin79 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-19-2007, 02:29 PM

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