środa, 23 września 2015

Data Scraping in Excel

1. Find text on sheet, return value next to it:

In a column:
=OFFSET(INDIRECT(ADDRESS(MATCH("Value of contract:*";$A$1:$A$100;0);1));0;1)


But I do not know where in the sheet it shows up? In that case an udf will be handy:
Public Function ValueNext2Descr(description As String)
    
    Application.Volatile
  
    ValueNext2Descr = ActiveSheet.Cells.Find(What:=description, _
    After:=Cells(1, 1), LookIn:=xlValues, _
    LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False).Offset(0, 1).Value

End Function

2. Find a table located between two strings (and then paste it somewhere else):



With Sheets("Output1").Columns(1)
         Set foundStart = .Find("Table title")
         Set foundEnd = .Find("Some text under the table")
End With

        
Set foundStart= foundStart.Offset(2, 1)
Set foundEnd = foundEnd.Offset(-1, 6)

Range(foundStart, foundEnd).Copy
Worksheets("Output2").Range("C1").PasteSpecial
        
Application.CutCopyMode = False


'also worth considering: http://stackoverflow.com/questions/17890004/using-an-or-function-within-range-find-vba

Brak komentarzy:

Prześlij komentarz