excel - If equals error in VBA -


so i've been having issue script , wondering if point me in right direction fix it.

i'm trying scan cell range , find value of "x", has align array (which seems working) finds value in range of columns greater 7.

option explicit  private sub worksheet_activate() dim ws worksheet dim lrow long dim rng range dim checks variant dim riskname variant dim level integer dim threatagent variant dim vulns variant  dim x integer dim y integer dim impactrange range dim impactcell range dim checksrange range dim checkscell range  me.usedrange.offset(17).clearcontents  x = 2 y = 1  sheets("ta & vul combinations")     .autofiltermode = false      set impactrange = .range("r3:r50")      each impactcell in impactrange.cells          if impactcell.cells > 7 , not isempty(impactcell.cells)             impactcell.copy             sheets("temp").range("b" & x).pastespecial xlpastevalues             x = x + 1         else          end if     next impactcell      set checksrange = .range("e3:e50")      each checkscell in checksrange.cells          if checkscell.cells("e3") = "x"             checkscell.copy             sheets("temp").range("c2:ao2").pastespecial xlpastevalues         else              range("k1") = "you broke it"         end if      next checkscell      .autofiltermode = false end  end sub 

if give me tips great

this line wrong:

if checkscell.cells("e3") = "x" 

since using cells property incorrectly.
cells property accepts numeric arguments.
syntax: cells(rowindex,colindex)

examples:

cells(1,1) 'refers range("a1") cells(1) 'refers range("a1") 

however, can use letters columns this:

cells(1,"a") 'refers range("a1") 

btw, work though.

if checkscell.range("e3") = "x" 

but take note of implications.
when use range.range syntax, happens use relative reference on first range.

example1:

range("b2").range("e3").address 

will give $f$4 because 5th (e) column , 3rd (3) row b2.

other examples:

range("c1:e10").range("b2").address 'refers $d$2 range("c1:e10").range("a1:b3").address 'refers $c$1:$d$3 

hope clear things bit.
don't know want achieve in code, not provide corrections.
can tell why getting errors.
if need additional help, revise question , clear major things up.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -