vba - How do you do a loop that can go through an entire column in an excel workbook and search for all instances of a string? -


im intern @ company lot of dcr , inductance readings , have values on text files. ive managed use vba import text files excel spreadsheet need start manipulating data. i'm trying write code loop through entire column , search string "**dcr" , give me data in cell offset (1,3), copy, , paste different range within same workbook. i've written code searches first instance of string , copies , pastes data need range, stops there. loop code wrote gives me infinite loop , doesnt work. here code far.

sub button2_click()  dim rng1 range dim strsearch string strsearch = "**dcr"  set rng1 = range("a:a").find(strsearch, , xlvalues, xlwhole) if not rng1 nothing     rng1.offset(1, 3).copy     range("n11").select     selection.pastespecial paste:=xlpastevalues, operation:=xlnone, skipblanks _         :=false, transpose:=false     range("o11").select             set rng1 = range("a:a").findnext(rng1)     loop end if  end sub 

can tell me i'm missing and/or doing wrong. thank much!

try this...

sub button2_click()  const dcr string = "**dcr"  dim rngsearch range set rngsearch = activesheet.range("a:a")  dim rngfoundfirst range  set rngfoundfirst = rngsearch.find(dcr, lookin:=xlvalues, lookat:=xlwhole, matchcase:=true) ' found? if not rngfoundfirst nothing     call processdcr(rngfoundfirst)      dim rngfoundnext range     set rngfoundnext = rngfoundfirst              set rngfoundnext = rngsearch.findnext(rngfoundnext)          ' if first 1 found, stop looping.         if not rngfoundnext nothing             if rngfoundnext.address = rngfoundfirst.address                 exit             end if              call processdcr(rngfoundnext)         end if     loop until rngfoundnext nothing end if  set rngfoundnext = nothing set rngfoundfirst = nothing set rngsearch = nothing  end sub  sub processdcr(rngfound range)  call rngfound.offset(1, 3).copy call range("n11").pastespecial(paste:=xlpastevalues, operation:=xlnone, skipblanks:=false, transpose:=false)  end sub 

Comments