excel - Walking Through Flagged Cells Individually -


i have stretch goal project goes way beyond current ability, hoping here put me on right track. have following code:

public errorcount integer  sub generalformat()     errorcount = 0     vlookup     macrofillareas     color     nonzerocompare     mustbe     msgbox ("number of errors" & cstr(errorcount)) end sub 

i have following section of code:

sub nonzerocompare() dim long = 5 1000 step 1     if range("ak" & i).value = "on"         if range("al" & i).value = 0 , range("am" & i).value = 0             range("al" & i, "am" & i).interior.colorindex = 6             errorcount = errorcount + 1         end if     elseif range("bc" & i).value = 0 , range("bd" & i).value = 0         range("bc" & i, "bd" & i).interior.colorindex = 6         errorcount = errorcount + 1     elseif range("ej" & i).value = "on"         if range("ek" & i).value = 0 , range("el" & i).value = 0             range("ek" & i, "el" & i).interior.colorindex = 6             errorcount = errorcount + 1         end if     elseif range("es" & i).value = 0 , range("et" & i).value = 0         range("es" & i, "et" & i).interior.colorindex = 6         errorcount = errorcount + 1     elseif range("fg" & i).value = 0 , range("fh" & i).value = 0         range("fg" & i, "fh" & i).interior.colorindex = 6         errorcount = errorcount + 1     end if next end sub 

my desired effect have user able jump each cell contributes "errorcount". there thousands of cells in workbook manage, being able jump error on review great. better if done 1 key on keyboard, button work too.

any ideas on how execute this? also, difficulty level? resources on begin on type of feature? last question: native features excel can code in use won't require hardcore coding?

here's approach work in handle requirements.

first, instead of holding count of number of errors, can hold dictionary object holds references cell locations. using object, can inspect total count of errors, locations, etc.

i'm going show 1 (relatively simple) implementation below. (if you're unfamiliar dictionary objects, research. basically, holds unique key , corresponding value). in case, chose store address of error cell key, , stored blank string value.

first, wrote function return dictionary object holding errors. in simple implementation, had fixed range, , stored in address of cell had text 'abc'.

next, wrote helper function returns count of number of objects (this simple enough don't need helper function, might simplify things if making multiple calls or if add more customized logic).

finally, 2 subroutines accomplish final req: traversing through errors. first routine 'traverseerrorsgoes through dictionary , "visits" each of addresses. yields adoeventscall allows user need to. thejumpahead` routine tells system user finished.

it helpful attach keyboard shortcut jumpahead method. so, while in excel workbook, press alt + f8 open macro window. select jumpahead routine, click options button in dialog box. allows enter letter when pressed along ctrl key, runs macro. (i selected letter e, ctrl + e allows me jump ahead once i've made changes).

there challenges consider. example, cell addresses not have reference sheet. therefore, if macro switches worksheets, may run trouble.

let me know of questions.

dim odictcellswitherrors object dim bcontinue boolean  private function geterrorsdict() object     dim rdata range     dim riterator range      'this helper function returns dictionary object containing errors     'if it's been populated     'if not, creates returns object      if not odictcellswitherrors nothing         set geterrorsdict = odictcellswitherrors         exit function     end if      'some logic create dictionary of errors     'in case, i'm adding cells have text "abc"     'your logic should differ      set rdata = sheet1.range("a2:a15")     set odictcellswitherrors = createobject("scripting.dictionary")      each riterator in rdata         if riterator.value = "abc"             if not odictcellswitherrors.exists(riterator.address)                 odictcellswitherrors(riterator.address) = ""             end if         end if     next riterator      set geterrorsdict = odictcellswitherrors end function  private function counterrors() integer     'this function returns number of errors in document     counterrors = geterrorsdict().count end function  sub traverseerrors()     dim odict object     dim skey variant      set odict = geterrorsdict()      each skey in odict.keys         bcontinue = false         sheet1.range(skey).activate          until bcontinue             doevents         loop     next skey      msgbox "no more errors" end sub  sub jumpahead()     bcontinue = true end sub 

Comments