+ Reply to Thread
Results 1 to 3 of 3

Search range for date, then capture details

Hybrid View

ks100 Search range for date, then... 06-15-2015, 11:56 AM
JoeFoot Re: Search range for date,... 06-15-2015, 12:05 PM
JOHN H. DAVIS Re: Search range for date,... 06-15-2015, 12:16 PM
  1. #1
    Forum Contributor
    Join Date
    09-04-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    298

    Search range for date, then capture details

    I've done similar to this before but it's been a while so I'm kind of rusty.

    I need to search a range (B2:ZZ500) for a date between today and variable X (X will be taken from a userform).

    For each date in the range after today but before X, I need it to do the following:

    Capture the column header value (so row 1 of whatever column it found the date in) as variable colheader

    Capture the row header value (column A of whatever row the date was found in) as variable rowheader

    (So if a matching date was found in B63, it would store the value in B1 as colheader and the value in A63 as rowheader.

    At this point another script will run that will populate a new worksheet with colheader and rowheader, and then move back to the original spreadsheet to search for the next date in the range meeting this criteria, and repeat the process until all applicable dates have been found (and captures into the new worksheet).

    I do not need help populating the new worksheet, I have the code for that part, I just need the rest of the script I described.

    Thanks!
    Last edited by ks100; 06-15-2015 at 11:58 AM.

  2. #2
    Registered User
    Join Date
    06-12-2015
    Location
    Maryland, USA
    MS-Off Ver
    2010
    Posts
    83

    Re: Search range for date, then capture details

    try this:

    
    
    Sub sort()
    
    Dim i As Integer
    Dim j As Integer
    Dim colheader As Variant 'if its number or text just adjust as needed
    Dim rowheader As Variant 'if its number or text just adjust as needed
    Dim variable_X As Date
    
    For i = 2 To 500
    
        For j = 2 To 702
                    
                If Cells(i, j) > VBA.Date And Cells(, j) < variable_X Then 'taken from useform
                        
                        colheader = Cells(1, j)
                        rowheader = Cells(i, 1)
                        
                        'code to populate worksheet here before the loop continues the search
                        
                        
                
                End If
        
        Next j
    
    Next i
    
    End Sub
    you might hit some snags with the date formats. Ensure that the date is properly formatted in the cells and coming out of your useform. I assumes variable_X is bigger than today's date. If not just adjust the instruction accordingly

    cheers
    Last edited by JoeFoot; 06-15-2015 at 12:10 PM.

  3. #3
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Search range for date, then capture details

    Maybe:

    Sub ks100x()
    Dim x As Date
    Dim y As Date
    Dim rcell As Range
    Dim ws As Worksheet
    Dim colheader As Long, rowheader As Long
    Set ws = ActiveSheet
    y = Date
    x = CDate("YOUR VARIABLE DATE")
    With ws
    For Each rcell In .Range("B2:ZZ500")
        If rcell.Value > y And rcell.Value < x Then
            colheader = rcell.column
            rowheader = rcell.row
        End If
        'Cells(rowheader, columnheader).Copy
        'YOUR OTHER CODE GOES HERE
    Next rcell
    End With
        
    End Sub

+ 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. Replies: 1
    Last Post: 10-14-2014, 07:17 AM
  2. [SOLVED] how can i search and copy details of a particular User details in Sheet1
    By baig123 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-10-2014, 02:58 AM
  3. Search large date range with narrow filetered range
    By druth in forum Excel General
    Replies: 14
    Last Post: 08-02-2014, 09:01 AM
  4. Search and paste corresponding details
    By haddo in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-22-2013, 04:20 AM
  5. Search date range +/- 7 days and return date that falls within range
    By tlafferty in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 07-13-2013, 03:26 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