+ Reply to Thread
Results 1 to 8 of 8

Extracting data from a range that changes daily based on a cells criteria

Hybrid View

JohnnyBoyxxx Extracting data from a range... 07-10-2014, 11:32 AM
mehmetcik Re: Extracting data from a... 07-10-2014, 08:43 PM
JohnnyBoyxxx Re: Extracting data from a... 07-11-2014, 06:34 AM
mehmetcik Re: Extracting data from a... 07-11-2014, 01:54 PM
JohnnyBoyxxx Re: Extracting data from a... 07-11-2014, 03:25 PM
JohnnyBoyxxx Re: Extracting data from a... 09-01-2014, 02:36 PM
mehmetcik Re: Extracting data from a... 09-01-2014, 03:39 PM
JohnnyBoyxxx Re: Extracting data from a... 09-02-2014, 02:35 AM
  1. #1
    Forum Contributor
    Join Date
    04-25-2011
    Location
    Donegal, Ireland
    MS-Off Ver
    Excel 2013
    Posts
    133

    Extracting data from a range that changes daily based on a cells criteria

    Hi, Everyday i receive an .xlsx file online.

    Once downloaded I have to extract specific areas of data from the file to a particular worksheet in another workbook.

    The source file has titles for ranges within the file which are constant but the rows of data beneath these titles vary on a daily basis.

    I am looking for a macro that will extract a range of data below a particular title.

    e.g. In the attached file (test sheet.xlsx) i want to extract A65-C122 into the worksheet 'new' in test sheet.xlsm (see attached).

    The range I've specified changes daily but the text in the titles stay the same albeit moved to different rows, daily also.

    I have spent the entire day trying to find a way using the Match function as recommended by 'nathansav', but my head is scrambled now at this stage.

    Any help would be a huge load off.

    Regards
    John
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Extracting data from a range that changes daily based on a cells criteria

    match is not the right funtion for what you are trying to do.

    Try this code:

    
    Sub Macro2()
    '
    ' Macro2 Macro
    '
    
    '
        Columns("A:A").Select
    
    
        Selection.Find(What:= _
            "HP Renew Notebooks - Grade Silver (Grade A) 1 Year Warranty", After:= _
            ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
            SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
    
    If ActiveCell.Value <> "HP Renew Notebooks - Grade Silver (Grade A) 1 Year Warranty" Then Exit Sub
    Startrow = ActiveCell.Row + 1
    
        Selection.Find(What:= _
            "Windows 8 Grade A Refurbished Notebooks & Netbooks 1 Year Warranty", After:= _
            ActiveCell, LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
            SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
    
    If ActiveCell.Value <> "Windows 8 Grade A Refurbished Notebooks & Netbooks 1 Year Warranty" Then Exit Sub
    Endrow = ActiveCell.Row - 1
    
        Range("A" & Startrow & ":C" & Endrow).Select
    
        Selection.Copy
        Sheets.Add After:=ActiveSheet
    
        ActiveSheet.Name = "New"
        Range("A1").Select
        ActiveSheet.Paste
        Range("A1").Select
    End Sub

  3. #3
    Forum Contributor
    Join Date
    04-25-2011
    Location
    Donegal, Ireland
    MS-Off Ver
    Excel 2013
    Posts
    133

    Re: Extracting data from a range that changes daily based on a cells criteria

    Hi mehmetcik, Thanks for your response. This looks really close to what I need.

    The thing is, I need to run this macro from worksheet 'new' in the 'test sheet.xlsm' workbook. So it will need go to workbook 'test sheet.xlsx', retrieve the data within the parameters you have set out and paste it back into 'test sheet.xlsm' workbook on the 'new' worksheet.

    If this is this possible.

    Thanks again

  4. #4
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Extracting data from a range that changes daily based on a cells criteria

    This is only a minor change.

    Your code becomes:-

    Note I have added a couple of lines to move any existing rows in sheet new down by the number of lines that you are copying.
    This will stop it over writing your existing data. The lines are easily identified and deleted if you don't want them.

    
    Sub Macro1()
    '
    ' Macro1 Macro
    '
    
    '
        Windows("test sheet.xlsx").Activate
        
            Columns("A:A").Select
    
    
        Selection.Find(What:= _
            "HP Renew Notebooks - Grade Silver (Grade A) 1 Year Warranty", After:= _
            ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
            SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
    
    If ActiveCell.Value <> "HP Renew Notebooks - Grade Silver (Grade A) 1 Year Warranty" Then Exit Sub
    Startrow = ActiveCell.Row + 1
    
        Selection.Find(What:= _
            "Windows 8 Grade A Refurbished Notebooks & Netbooks 1 Year Warranty", After:= _
            ActiveCell, LookIn:=xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, _
            SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Activate
    
    If ActiveCell.Value <> "Windows 8 Grade A Refurbished Notebooks & Netbooks 1 Year Warranty" Then Exit Sub
    Endrow = ActiveCell.Row - 1
    
        Range("A" & Startrow & ":C" & Endrow).Select
    
        Selection.Copy
    
        Windows("test sheet.xlsm").Activate
        Sheets("new").Select
        
    'Delete these rows if you want your data overwritten.  But if your existing data is longer that the new, you will end up with a mess.
    
        Rows("2:" & 1 + Endrow - Startrow).EntireRow.Select
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        
        Range("A2").Select
        ActiveSheet.Paste
        Range("A1").Select
        
    End Sub
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    04-25-2011
    Location
    Donegal, Ireland
    MS-Off Ver
    Excel 2013
    Posts
    133

    Re: Extracting data from a range that changes daily based on a cells criteria

    mehmetcik, this worked perfectly, exactly what i was looking for.

    Many many thanks

    John
    Last edited by JohnnyBoyxxx; 07-11-2014 at 03:35 PM. Reason: typo

  6. #6
    Forum Contributor
    Join Date
    04-25-2011
    Location
    Donegal, Ireland
    MS-Off Ver
    Excel 2013
    Posts
    133

    Re: Extracting data from a range that changes daily based on a cells criteria

    Hi mehmetcik, Is there a way to repeat the code to select additional data using the same formula but with different start and end rows, and then add it to the 'new' sheet at the first free blank cell in column A

    Regards
    John

  7. #7
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Extracting data from a range that changes daily based on a cells criteria

    Easily done.

    Original range was A65-C122

    What is the new range

  8. #8
    Forum Contributor
    Join Date
    04-25-2011
    Location
    Donegal, Ireland
    MS-Off Ver
    Excel 2013
    Posts
    133

    Re: Extracting data from a range that changes daily based on a cells criteria

    Additionally i would like to include in the final results the section below row 132 'Windows 7 Grade A Refurbished Notebooks & Netbooks 1 Year Warranty' and above row 176 'Acer Vista / XP Notebooks – Refurbished 1 Year Warranty - Upgrade any notebook to Windows 7 for £29 + Vat'. So the range is A131-C175

    Thx Mehmetcik

+ 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. Daily Pivot Filter based on Date range specified in cells
    By swicked in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-02-2012, 01:23 AM
  2. [SOLVED] #NUM! Error with Extracting Data Based on Criteria
    By ACM2 in forum Excel General
    Replies: 15
    Last Post: 06-28-2012, 02:38 PM
  3. Replies: 2
    Last Post: 11-19-2010, 07:49 AM
  4. Help Extracting Data Based On two Criteria
    By chadha.hitesh in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 11-09-2010, 11:08 AM
  5. Extracting Data Based on Criteria
    By SJT in forum Excel General
    Replies: 3
    Last Post: 06-16-2007, 04:18 PM

Tags for this Thread

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