+ Reply to Thread
Results 1 to 14 of 14

Filtering data and posting results to another sheet

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-30-2005
    Location
    Penzance Cornwall, UK
    MS-Off Ver
    Office 365
    Posts
    198

    Filtering data and posting results to another sheet

    I would like a macro asking for “beginning” and “ending” dates, then asking for “Car Make”

    Based on the result, on sheet2, starting on cell B6, show the result, which would include: the Make, Date, Region No, S or H, and the number sold, along with the total, but not to show zero or empty cells.

    Allow the user to edit sheet2 (highlight, comment) print it, clear contents, etc.

    Can any such macro, then retain the dates (until the workbook is closed), so if the macro is called again, it would ask “In the same period, what Make would you like to report on” and then repeat the process.
    Attached Files Attached Files

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Filtering data and posting results to another sheet

    Hi kjg

    The Code in the attached appears to do as you require. Please note this Code in the Workbook Open Event.
    Option Explicit
    
    Private Sub Workbook_Open()
      Dim ws As Worksheet, ws1 As Worksheet
      Dim LR As Long, LC As Long
    
      Set ws = Sheets(1)
    
      Application.ScreenUpdating = False
      If Not Evaluate("ISREF(Lists!A1)") Then
        Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Lists"
      Else
        Sheets("Lists").Cells.ClearContents
      End If
      Set ws1 = Sheets("Lists")
      ws1.Range("B1").Value = "Models"
    
      With ws
        .Activate
        LR = .Range("A" & .Rows.Count).End(xlUp).Row
        LC = .Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByColumns, _
                         SearchDirection:=xlPrevious).Column
        .Range("A2:A" & LR).AdvancedFilter Action:=xlFilterCopy, _
                                           CopyToRange:=ws1.Range("A1"), Unique:=True
    
        ActiveWorkbook.Names.Add Name:="Dates", RefersTo:= _
                                 "=OFFSET(Lists!$A$2,0,0,(COUNTA(Lists!$A:$A)-1),1)"
    
        .Range(.Cells(2, "E"), .Cells(2, LC)).Copy
        ws1.Range("B2").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
                                     False, Transpose:=True
        ActiveWorkbook.Names.Add Name:="Models", RefersTo:= _
                                 "=OFFSET(Lists!$B$2,0,0,(COUNTA(Lists!$B:$B)-1),1)"
      End With
      Application.CutCopyMode = False
      Application.ScreenUpdating = True
    End Sub
    Attached Files Attached Files
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Forum Contributor
    Join Date
    11-30-2005
    Location
    Penzance Cornwall, UK
    MS-Off Ver
    Office 365
    Posts
    198

    Re: Filtering data and posting results to another sheet

    Hi Jaslake,

    Thanks for the code.

    I press the "Make Selection" button and choose a start date and end date then model, when I press the "Extract Data" button, I get a dialog box asking again for Start Date. If I repeat the process, I get the same dialog.

    What do you think??

    Keith

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Filtering data and posting results to another sheet

    Hi Keith

    You get that on your Sample File???

  5. #5
    Forum Contributor
    Join Date
    11-30-2005
    Location
    Penzance Cornwall, UK
    MS-Off Ver
    Office 365
    Posts
    198

    Re: Filtering data and posting results to another sheet

    Hi Again,

    Yea /no, I get it on the data / file you sent back to me, downloaded and saved.

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Filtering data and posting results to another sheet

    Hi Keith

    Well, I don't know what to think. Tested the Code in both Excel 2007 and 2010. Runs just fine on my platform.

    I want you to put a Break Point at the line of Code as indicated. Then click the Make Selection Button. When you see the VBA screen step through the Code (F8). Tell me what's it's doing. I cannot duplicate the error.
    Attached Images Attached Images

  7. #7
    Forum Contributor
    Join Date
    11-30-2005
    Location
    Penzance Cornwall, UK
    MS-Off Ver
    Office 365
    Posts
    198

    Re: Filtering data and posting results to another sheet

    Good Morning,

    I did as you suggested and placed a breakpoint on the "With Me" line and pressed the button, I then pressed the F8 key and stepped through the code. The code goes through the MsgBox and then displays the message "Please enter a Start Date".

    If I REM that block of code it does the same again for the end date "Please enter a End Date", if I REM that bit of code also it runs fine, suggesting that the date is the problem.

      With Me
        If .ComboBox1.ListIndex = -1 Then
          MsgBox "Please enter a Start Date"
          GoTo EarlyExit
    I noticed that although I select, say, 15/01/2014 the dialog would display 1/15/2014. Not knowing what I am doing, I changed the below code from

    Private Sub ComboBox1_Click()
      Me.ComboBox1.Value = Format(Me.ComboBox1.Value, "m/d/yyyy")
    End Sub
    TO

    Private Sub ComboBox1_Click()
      Me.ComboBox1.Value = Format(Me.ComboBox1.Value, "dd/mm/yyyy")
    End Sub
    This displayed my selection correctly but then I get a dialog "No cells were found"

    Regards,
    Keith

  8. #8
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Filtering data and posting results to another sheet

    Hi Keith

    I really have no clue unless it's related to the Regional Setting. What is yours?

  9. #9
    Forum Contributor
    Join Date
    11-30-2005
    Location
    Penzance Cornwall, UK
    MS-Off Ver
    Office 365
    Posts
    198

    Re: Filtering data and posting results to another sheet

    My Regional Setting are English UK

  10. #10
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Filtering data and posting results to another sheet

    Hi Keith

    After changing my Regional Settings I'm having issues...need to play with it for a bit...see what, if anything I can do. I'm not familiar with this issue but I will be

  11. #11
    Forum Contributor
    Join Date
    11-30-2005
    Location
    Penzance Cornwall, UK
    MS-Off Ver
    Office 365
    Posts
    198

    Re: Filtering data and posting results to another sheet

    Thank s very much.......I await the outcome. Also, is there any chance that you could add some comments to your code as I'd like to "try" and understand it a little and try to learn from it.

    Cheers,
    Keith

+ 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] Filtering Data and copying only filtered results
    By bigfishprf in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-07-2013, 07:51 AM
  2. Filtering data from the results of a sumifs formula
    By marks_28 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-27-2013, 11:55 AM
  3. Filtering Results and Copying Each Result to a Seperate Sheet
    By gjaylward2008 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-16-2012, 04:10 PM
  4. As user fills out data sheet, then fill out a results sheet based on data sheet entry
    By clemsoncooz in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-13-2012, 03:57 PM
  5. filtering data from multi sheets then performing functions on results
    By jrtaylor in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-26-2009, 03:54 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