Results 1 to 10 of 10

Thread: [RESOLVED] Selecting data for extraction

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Location
    Oxford UK
    Posts
    76

    Resolved [RESOLVED] Selecting data for extraction

    I have put together this excel form for collecting data which is working well. What I now want is to have a way of selecting a starting and ending date for the dates of the data I want to extract from the data list, to an external workbook.I want to do this from another form, maybe by using a date picker method. I have attached the file, there are 2 passwords, "getmein" will open the workbook and "start" will open the form. I am a total newbie and this will be a great help as I have no idea where to start.
    Thanks

  2. #2
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Selecting data for extraction

    Try the following. The Test procedure is just to show you the main ExportData procedure in action.
    VB Code:
    1. Option Explicit
    2.  
    3. Sub Test()
    4.     ExportData "12/01/2005", "12/31/2005"
    5. End Sub
    6.  
    7.  
    8. Sub ExportData(dStartDate As Date, dEndDate As Date)
    9. Dim wksDataSheet As Worksheet
    10. Dim wkbExport As Workbook
    11.    
    12.     'The worksheet to be exported
    13.     Set wksDataSheet = Worksheets("IquaDB")
    14.    
    15.     'Turn off any existing filters
    16.     wksDataSheet.AutoFilterMode = False
    17.    
    18.     'Filter the data based on the passed date parameters
    19.     wksDataSheet.Range("A1").AutoFilter _
    20.         field:=1, _
    21.         Criteria1:=">=" & dStartDate, _
    22.         Operator:=xlAnd, _
    23.         Criteria2:="<=" & dEndDate
    24.    
    25.     'Add a new workbook
    26.     Set wkbExport = Application.Workbooks.Add
    27.    
    28.     'Copy the data to the new book
    29.     wksDataSheet.Range("A:J").Copy Destination:=wkbExport.Worksheets(1).Range("A1")
    30.    
    31.     'Clear the clipboard
    32.     Application.CutCopyMode = False
    33.    
    34.     'Turn the filters off
    35.     wksDataSheet.AutoFilterMode = False
    36.        
    37.     'Clear the object variables
    38.     Set wksDataSheet = Nothing
    39.     Set wkbExport = Nothing
    40. End Sub
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Location
    Oxford UK
    Posts
    76

    Re: Selecting data for extraction

    Excellent Dkenny

    What I have done is created a couple of date pickers to select the dates from a form but its not quite working.
    Code:
    Private Sub cmdOk2_Click()
    Dim dStartDate As Date
    Dim dEndDate As Date
    
    dStartDate = dpStart()
    dEndDate = dpEnd()
     
     ExportData dStartDate, dEndDate
    End Sub
    The date pickers have got there day and month format back to front. Can I tell it to use dd/mm/yyyy format instead??
    Last edited by thelocaluk; Feb 10th, 2006 at 07:04 AM.

  4. #4
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Selecting data for extraction

    Change the datatype on dStartDate and dEndDate to Long.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Location
    Oxford UK
    Posts
    76

    Re: Selecting data for extraction

    Quote Originally Posted by DKenny
    Change the datatype on dStartDate and dEndDate to Long.
    Sorry to be a bit thick
    How do I do that?

  6. #6
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Selecting data for extraction

    VB Code:
    1. Private Sub cmdOk2_Click()
    2. Dim dStartDate As Long
    3. Dim dEndDate As Long
    4.  
    5. dStartDate = dpStart()
    6. dEndDate = dpEnd()
    7.  
    8.  ExportData dStartDate, dEndDate
    9. End Sub
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Location
    Oxford UK
    Posts
    76

    Re: Selecting data for extraction

    Did that, but it now come ups with a ByRef argument type mismatch at the ExportData line.

  8. #8
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Selecting data for extraction

    try changing
    Sub ExportData(dStartDate As Date, dEndDate As Date)
    to
    Sub ExportData(ByVal dStartDate As Date, ByVal dEndDate As Date)
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Nov 2005
    Location
    Oxford UK
    Posts
    76

    Re: Selecting data for extraction

    Hey DKenny, I changed the
    Sub ExportData(dStartDate As Date, dEndDate As Date)
    to
    Sub ExportData(dStartDate As Long, dEndDate As Long)
    and that seems to be working just great.
    Your an absolute guru, many thanks for all your help.

    P.S I've read many post here as a keen newbie to VB and often come across your name. Keep up the good work, its a great help to people like me.

  10. #10
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Selecting data for extraction

    Thanks, glad I could help.
    Don't forget to mark your post as resloved
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width