+ Reply to Thread
Results 1 to 8 of 8

Macro update to sort between two dates

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-05-2004
    MS-Off Ver
    Office 365
    Posts
    651

    Macro update to sort between two dates

    As the macro runs now it gives you the option to choose a salesman (Sheet2 B1) and a maximum date (Sheet2 B2) and then it does its breaks down.

    I need to add two more levels of functionality which are obviously beyond my VBA ability.

    1) I need to add a minimum date (Sheet2 B3) so eventually you are able to give the beginning and ending dates for the search.
    2) I need to also add the ability (you can see I added “ALL” to the drop down menu (Sheet2 B1) to choose ALL salesmen and have the macro then break down the lists including them all.

    Thank you for your assistance.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro update to sort between two dates

    Between dates meant <max and >min.
    Attached Files Attached Files

  3. #3
    Forum Contributor
    Join Date
    05-05-2004
    MS-Off Ver
    Office 365
    Posts
    651

    Re: Macro update to sort between two dates

    In between dates is working great but the ALL function seems to not. What I would like it to do is just ignore the salesmen names and just sort them into the correct columns.

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro update to sort between two dates

    Where are the names of sales man? I thought, you use sales man as the value to find. Did you check the result in sheet2. All I did to you code is to include all sales man, that is, all names in column B needs to be searched.

  5. #5
    Forum Contributor
    Join Date
    05-05-2004
    MS-Off Ver
    Office 365
    Posts
    651

    Re: Macro update to sort between two dates

    Sales names are H2:H6 on sheet1.
    When i say ALL and run the macro now. it should show all data for each color ignoring the salesmen. It looks now like its repeating.

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro update to sort between two dates

    No, I am missing something. The code you have selects the sales man from B1 and finds all, let's say, Tim's data.
    By ALL, you meant you want to select all sales men. Is this right? If so, you have repeated names in column B. Please include a sample out put.

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro update to sort between two dates

    Sorry!
    You are right! It is repeating, so I need to use a unique column names which is column H.
    Attached Files Attached Files

  8. #8
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,086

    Re: Macro update to sort between two dates

    A tempoarary solution just for the Min and Max Dates
    Option Explicit
    Sub subgen99a()
    Dim ws1  As Worksheet, ws2 As Worksheet
    Set ws1 = Sheets("Sheet1") 'change as necessary
    Set ws2 = Sheets("Sheet2") ' "
    Dim Min_Date  As Date, Max_Date As Date, WkDate As Date
    Dim WkName  As String
    Dim c, d
    Dim r As Integer
    Dim firstAdd As String
    ws2.Range("J2:" & ws2.Columns("J:Q").SpecialCells(11).Address).ClearContents ' clear the color table
    
    WkName = ws2.[B1] ' the name to look for
    Min_Date = ws2.[B3]
    Max_Date = ws2.[B2]
    
       Set c = ws1.Columns(2).Find(WkName, lookat:=xlWhole) 'search for the name
       If Not c Is Nothing Then 'if the name is found
           firstAdd = c.Address 'noting the first found cell
           Do ' now we're gonna add data to the approiate columns using a Do Loop
               Set d = c 'we need to do this b/c we're gonna search for the right color column
               Set c = ws2.Rows(1).Find(c.Offset(0, 1).Value) ' look for the column color
               If Not c Is Nothing Then
                   If ((d.Offset(0, -1) >= Min_Date) And (d.Offset(0, -1) <= Max_Date)) Then
                      r = ws2.Cells(Rows.Count, c.Column).End(3).Row + 1 'The empty row in the color column
                      ws2.Cells(r, c.Column).Value = d.Offset(0, -1).Value 'the date
                      ws2.Cells(r, c.Column + 1).Value = d.Offset(0, 2).Value 'the amount
                   End If
               End If
             Set c = ws1.Columns(2).Find(WkName, lookat:=xlWhole, after:=d) 'find the next name
           Loop While Not c Is Nothing And c.Address <> firstAdd
       End If
    End Sub
    - Battle without fear gives no glory - Just try

+ 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. [SOLVED] Help with Macro (now to sort by dates)
    By pennbowl in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-07-2014, 07:07 AM
  2. Replies: 1
    Last Post: 09-14-2014, 02:10 PM
  3. [SOLVED] update Sort Macro
    By summer2010 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-16-2013, 05:21 AM
  4. Macro to sort pivot tables and only show dates for current week.
    By jcranst in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-01-2013, 08:06 AM
  5. Custom Sort Macro - Update on Data Entry
    By cuso524 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-21-2010, 01:38 PM
  6. Macro to update specified dates automatically
    By mrcois in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-03-2010, 03:36 PM
  7. Get macro to sort dates properly
    By DamienC in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-21-2008, 02:53 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