VBA Excel; Finding Duplicate Cells and Populating an Offset Cell -


i creating automated system reads data wirelessly transmitted data excel. data sends gauge number , value ex. 89,-.002 (gauge #89, value=-.002). data goes cell f2. have created code separates the gauge number , value variables. have list of fixed gauge numbers in cell c5-c11 , readings populate offset in cells g5-g11 based on gauge number. haven't been able figure out how take readings same gauge multiple reading if needed check multiple spots on part. example if there 3 different readings needed gauge 87 ( 87 listed 3 times in c5-c11), need code search 87 based off gauge number variable input in f2 , find 87's in cells c5-c11. check if cell offset 4 columns has value already. if move on next 87 found , check if offset on 1 has value. if doesn't populate cell.

i can't hard code numbers in because creating template. have search multiples gauge numbers believe.

any or ideas appreciated. better if can give me sample code integrate project.

set wsinput = sheet1 wsinput.range("c5:c24") 'selects sheet 1 range

dim c range dim gagenum string dim reading string dim mystring string dim stringlen single dim location single dim gloc single dim count single dim answer integer dim count1 single dim single  mystring = range("f2").value 'identifies cell data in f2 string variable location = instr(mystring, ",") + 1 'finds comma separator , adds 1 not include comma gloc = instr(mystring, ",") - 1 'finds location of comma , goes 1 rid of comma. 'msgbox location 'tests see character starting @ stringlen = len(mystring) - location + 1 'creates new string has length of remaining characters reading = mid(mystring, location, stringlen) 'reads string after comma until end of string 'msgbox reading 'test see if gets correct reading gauage  gagenum = left(mystring, gloc) 'finds gauge number searching left of comma 'msgbox gagenum 'test of guage number set c = .find(gagenum, lookin:=xlvalues) if not c nothing     dim firstaddress string     dim rslt string     firstaddress = c.address             rslt = rslt & c.address & ","        set c = .findnext(c) loop while c.address <> firstaddress     'msgbox left(rslt, len(rslt) - 1)     end if     end  if len(c.offset(, 4)) = 0     range("f2").select     c.offset(, 4) = reading 'populates cell reading.  else     answer = msgbox("error: gauge " & c & " measurement has been taken." & vbnewline & "do want use new measurement instead?", vbyesno + vbquestion, "re-measure?")         if answer = vbyes             range("f2").select             c.offset(, 4) = reading 'populates cell reading.         else             'do nothing         end if end if 

thats have doesnt search duplicates first 1 finds.

it's problem do...loop while section. putting while condition @ end that, you're telling continue looping until c.address = firstaddress. instead of automatically setting c next 1 here: set c = .findnext(c), should test first determine whether findnext gives address want. this:

set tempc = .findnext(c) if tempc.address <> firstaddress     set c = tempc else     exit end if 

note: set c last place gauge number appears, not next one. next one, replace findnext findprevious. loop in reverse order , wind @ second instance of gauge number.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -