Consulting

Results 1 to 5 of 5

Thread: Selecting a range based on a date range

  1. #1

    Selecting a range based on a date range

    Hi, I am new to this forum and need some help with some code, I want to be able to use a cmdsubmitfunction where when entering a date into a text box and clicking cmdsubmit the code is able to select a range of rows based on the date in column A containing the current days date -6days then take that selection and paste into a body of an email. Any ideas??

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I think an example workbook would help, with details of what data is to be extracted from that example.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Date Entered Contract Service Call Severity Service Site 30/04/2013 21/04/2013

  4. #4
    Hi, Having issues adding the workbook, basically rows of data are entered throughout a 7day period I want the code to select a range based on the current date and each date previous upto 6days so the range would select all data entries which contained the last 7days dates. in Column A E.g. if I ran it today the code would select all rows which contained Todays date (01/05/13) and dates 6 days back - 30/04/13, 29/04/13, 28/04/13, 27/04/13, 26/04/13 25/04/13.

    If that adds more clarity to my query.

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [VBA]
    Sub CopyData()
    Dim rng As Range
    Dim lastrow As Long

    With ActiveSheet

    lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
    Set rng = .Range("A1").Resize(lastrow)
    rng.AutoFilter Field:=1, _
    Criteria1:="<=" & Format(Date, .Range("A2").NumberFormat), _
    Operator:=xlAnd, _
    Criteria2:=">" & Format(Date - 7, .Range("A2").NumberFormat)
    rng.SpecialCells(xlCellTypeVisible).Copy

    'then do something with the copied range
    End With
    End Sub[/VBA]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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