vba to set up a dynamic range based on two column -


i trying set dynamic range based on 2 column, criteria is...

  1. i have 2 columns called "name" , "phone"
  2. column "name" in left side of "phone"

range wish is,

  1. find column "phone"
  2. set range in column "phone" 1st non-empty row , last row in column "name"

so far able find column "phone" , remaining stuff not able relate range column "name", please see below macro , suggest how should able it.

hey in advance...

    option explicit  sub rulepicker()     dim ws worksheet     dim acell range, rng range     dim col long, lrow long     dim colname string      '~~> change relevant sheet     set ws = thisworkbook.sheets("sepy build")      ws         set acell = .range("a1:zz1").find(what:="phone", lookin:=xlvalues, lookat:=xlwhole, _                     matchcase:=false, searchformat:=false)          '~~> if found         if not acell nothing             col = acell.column             colname = split(.cells(, col).address, "$")(1)              lrow = .range(colname & .rows.count).end(xlup).row              '~~> range             set rng = .range(colname & "13:" & colname & lrow)                 rng.formula = "=if(rc[-9]="""","""",if(left(lower(rc[-9]),4)=""none"","""",vlookup(left(rc[-9],(find("" "",rc[-9],1)-1)),'base rule'!c[-10]:c[-5],2,0)))"                 rng.value = rng.value                 rng.offset(0, 1).formular1c1 = "=if(rc[-1]="""","""",vlookup(rc[-1],rules!c[-12]:c[-11],2,0))"                 rng.offset(0, 2).formular1c1 = "=if(rc[-11]="""","""",if(left(lower(rc[-11]),4)=""none"","""",vlookup(left(rc[-11],(find("" "",rc[-11],1)-1)),'base rule'!c[-12]:c[-7],3,0)))"                 rng.offset(0, 2).value = rng.offset(0, 2).value                 rng.offset(0, 3).formular1c1 = "=if(rc[-12]="""","""",if(left(lower(rc[-12]),4)=""none"","""",vlookup(left(rc[-12],(find("" "",rc[-12],1)-1)),'base rule'!c[-13]:c[-8],4,0)))"                 rng.offset(0, 3).value = rng.offset(0, 3).value                 rng.offset(0, 4).formular1c1 = "=if(rc[-1]="""","""",vlookup(rc[-1],rules!c[-15]:c[-14],2,0))"                 rng.offset(0, 5).formular1c1 = "=if(rc[-14]="""","""",if(left(lower(rc[-14]),4)=""none"","""",vlookup(left(rc[-14],(find("" "",rc[-14],1)-1)),'base rule'!c[-15]:c[-10],5,0)))"                 rng.offset(0, 5).value = rng.offset(0, 5).value             debug.print rng.address         '~~> if not found         else             msgbox "phone header not found"         end if     end end sub 


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -