Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. Sub SearchTerms()
  2. Dim folderPath As String
  3. Dim filename As String
  4. Dim wb As Workbook
  5. Dim n As Long
  6. Dim cell As Range
  7. Dim curr As Range
  8. Dim found As Boolean
  9. Dim foundTerm As Boolean
  10. Dim myArray As Variant
  11.  
  12. folderPath = 'pathname goes here
  13.  
  14. If Right(folderPath, 1) <> "" Then folderPath = folderPath + ""
  15.  
  16. filename = Dir(folderPath & "*.xls")
  17. Do While filename <> ""
  18. Application.ScreenUpdating = False
  19. Application.Calculation = xlCalculationManual
  20. Set wb = Workbooks.Open(folderPath & filename)
  21. On Error GoTo 0
  22.  
  23. For i = 1 To 10
  24. If Not IsEmpty(Cells(i, "D")) Then
  25. Exit For
  26. End If
  27. Next
  28.  
  29. found = False
  30. n = Workbooks("jan17 search terms").Sheets("Sheet1").Range("B" & Rows.Count).End(xlUp).Offset(1).Row
  31. For Each curr In Range("A" & i, "Z" & i)
  32. If InStr(1, curr.Value, "Protein", vbTextCompare) > 0 Or InStr(1, curr.Value, "Phosphosite", vbTextCompare) > 0 Or InStr(1, curr.Value, "Accession", vbTextCompare) > 0 Or InStr(1, curr.Value, "Uniprot", vbTextCompare) > 0 Then
  33. For Each cell In ActiveWorkbook.ActiveSheet.UsedRange
  34. If InStr(1, cell.Value, "search term", vbTextCompare) > 0 Then
  35. Workbooks("jan17 search terms").Sheets("Sheet1").Cells(n, 2).Value = "Yes"
  36. foundTerm = True
  37. Exit For
  38. End If
  39. Next
  40. Exit For
  41. End If
  42. Next
  43.  
  44. If Not foundTerm Then Workbooks("jan17 search terms").Sheets("Sheet1").Cells(n, 2).Value = "-"
  45.  
  46. 'prints filename on the side
  47. n = Workbooks("jan17 search terms").Sheets("Sheet1").UsedRange.Rows(Workbooks("jan17 search terms").Sheets("Sheet1").UsedRange.Rows.Count).Row
  48. Workbooks("jan17 search terms").Worksheets("Sheet1").Cells(n, 1).Value = filename
  49.  
  50. wb.Close
  51. filename = Dir
  52. Loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement