excel vba - application-defined or object-defined error in cell range visual basic -


having problems code below. i'm getting application-defined or object-defined error in initiation of second loop. format of second loop range seems causing problem. removing sheets() object gets rid of error, script reads wrong worksheet, , doesn't return data.

the goal of code loop on vertical array of data, , if match selection dropdown found, loops on horizontal array of data , returns color change if finds 'yes' value.

if not intersect(target, range("countryproductcell")) nothing     lastcolumn = activesheet.usedrange.column - 1 + activesheet.usedrange.columns.count     dim cellrow integer     cellrow = target.row     dim defaultcellcolumn integer     defaultcellcolumn = 4     = 5     j = 1     k = 1     if not cells(cellrow, defaultcellcolumn).value = "(select title)"         each countrycell in range(cells(cellrow, defaultcellcolumn + 1), cells(cellrow, lastcolumn))             if countrycell.value = "use default"                 countrycell.interior.colorindex = 3             end if         next         each namecell in sheets("active product catalog").range("productnames")             if namecell.value = cells(cellrow, defaultcellcolumn).value                 'error on line below!                 each purchaseablecell in sheets("active product catalog").range(cells(namecell.row, 10), cells(namecell.row, 27))                     if purchaseablecell.value = "yes"                         'if purchaseable, change color                         sheets("home template").cells(cellrow, defaultcellcolumn + j).interior.colorindex = 35                     end if                     j = j + 1                 next             end if             k = k + 1         next     elseif cells(cellrow, defaultcellcolumn).value = "(select title)"         if target.value = "(select title)"             target.interior.color = cells(target.row, target.column - 1).interior.color             each countrycell in range(cells(cellrow, defaultcellcolumn + 1), cells(cellrow, lastcolumn))                 if countrycell.value = "use default"                     countrycell.interior.colorindex = 2                 end if                 = + 1             next         elseif target.value = "use default"             target.interior.colorindex = 2         elseif application.vlookup(activesheet.cells(cellrow, target.column), sheets("active product catalog").range("e:ak"), target.column, false) = "yes"             target.interior.colorindex = 35         elseif not application.vlookup(activesheet.cells(cellrow, target.column), sheets("active product catalog").range("e:ak"), target.column, false) = "yes"             target.interior.colorindex = 3         end if     end if end if 

you need qualify cells references in code. reason failing using 2 cell references 1 sheet (the active sheet) , asking vba define range in sheet (active product catalog). try this:

sheets("active product catalog").range(sheets("active product catalog").cells(namecell.row, 10), sheets("active product catalog").cells(namecell.row, 27)) 

you'll find bit easier read if create worksheet object or use statement.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -