excel vba - Having Trouble passing a Cell object? (i could be wrong) -


first off thank much. on last few months (i believe) coding has progressed drastically. , criticize welcome (rip me apart).

recently started try use different subs (i dont quite understand when use functions etc, figure structure practice when figure out.

i hitting run-time 424 error following bit of code in sub ownercheck

sub occupationnormalization()      dim infobx string      ' initialize variables     lrow = activesheet.usedrange.rows.count     lcol = activesheet.usedrange.columns.count     statuscounter = lrow          while infobx = ""             infobx = inputbox("enter occupation column", "occupation column")         loop                restaurcheck (infobx)  application.screenupdating = true application.statusbar = "" end sub 

-

sub restaurcheck(infobx string)     dim restaurants(), restaurantdqs() variant     dim i, lrow, lcol, statuscounter long     dim rrng range          lrow = activesheet.usedrange.rows.count         lcol = activesheet.usedrange.columns.count         statuscounter = lrow restaurants = array("estaur", "food", "cafe", "beverage", "waiter", "waitr", _                 "waitstaff", "wait staff", "grill") 'array list of target occupations   restaurantdqs = array("fast", "pub", "import", "packing", "processing", "packag", _                 "retired", "anufact", "distrib") ' disqualifying words restaurante category  set rrng = range(infobx & "2:" & infobx & lrow)  application.screenupdating = false     each cell in rrng         ownercheck (cell)         = lbound(restaurants) ubound(restaurants)                 if instrrev(cell.value, ucase(restaurants(i))) > 0                     cell.offset(, 1) = "restaurants"                     cell.interior.color = 52479                 end if             debug.print cell.value         next          = lbound(restaurantdqs) ubound(restaurantdqs)             if instrrev(cell.value, ucase(restaurantdqs(i))) , cell.interior.color = 52479                 cell.interior.color = 255                 cell.offset(, 1) = ""               end if          next                      statuscounter = statuscounter - 1                     application.statusbar = "remaining rows " & statuscounter & "           tristram "      next cell   end sub 

-

sub ownercheck(str_owner range)    dim owner() variant    owner() = array("owner", "shareholder", "owns ")         = lbound(owner) ubound(owner)                 if instrrev(str_owner, ucase(owner(i))) > 0                     cell.offset(, 2) = "owner"                  end if         next  end sub 

i can see couple of issues in ownercheck():

  • "cell" not defined (unless it's global)
  • you shouldn't use "cell" variable name (internal vba property)
  • check validity of incoming range

.

option explicit  sub ownercheck(byref rngowner range)      if not rngowner nothing          dim owner() variant         owner() = array("owner", "shareholder", "owns ")          = lbound(owner) ubound(owner)             if instrrev(ucase(rngowner), owner(i)) > 0                 rngowner.offset(, 2) = "owner"             end if         next      end if  end sub 

Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -