1

I got 1000s of rows of URLs and for each row I am using:

For i = 2 to last row
Set links = html.getElementsByTagName("a")
For Each lnk In links
If lnk.innertext = "something" then
do something
end if
Next lnk
Next i

a method coomonly used, I guess, and as a ref shown by Sid's code at How to access innerText of HTML tag inside a <TD> tag

Is For loop (the one for each lnk), pretty much the only method in this scenario or are there faster efficient methods? MATCH is probably used only for sheet ranges, but tried it anyways. It runs w/o error, does nothing and takes the same time as the For loop method. I think it does nothing due to the lack of appropriate addressing in :

If Not IsError(Application.Match("something", Range("A1:A100"), 0))  'normally used for ranges
If Not IsError(Application.Match("something", links.innertext, 0))  'what I tried
Community
  • 1
  • 1
Sandy
  • 59
  • 2
  • 13
  • The inner loop you have is pretty much how you do it: the only way to speed things up would be if you had some way to select only a subset of the links, based (eg) on some particular CSS class or other attribute. What's the purpose of your outer `i` loop here? – Tim Williams Mar 09 '14 at 23:55
  • @TimWilliams We truely live in a quantun entangled world - i just tetsted your code at http://stackoverflow.com/questions/18754096/matching-values-in-string-array - and was getting hopeful on saving some good macro time if I can write a function at least for my inner loop - when I saw your response :>) The outer i loop is for going to next row until LR – Sandy Mar 10 '14 at 02:11
  • @TimWilliams The inner loop has a few conditions and sequences: if corresponding cell in column F = "", then if lnk.innertext = (searchstring1) then put that lnk & innertext in cell column F & G, exit inner loop and go to next outer i loop - row(i). Repeat for some more searchstrings, INSTR and other search conditions as long as cell in column F = "". – Sandy Mar 10 '14 at 02:28
  • Still unsure what you're doing: are you searching the same collection of links against a bunch of rows? Then at least do the `Set links` line before starting the outer loop. – Tim Williams Mar 10 '14 at 23:42

0 Answers0