excel - Capitalize Dynamic Range in VBA -


(coding rookie posting first ever question please pardon mistakes)

i'm trying learn simple methods of data validation. read post similar i'm doing: convert-entire-range-to-uppercase, doesn't work when change range fit needs. couldn't find else addressed this.

i have excel column named "block" appears in different locations in different workbooks, , need capitalize letters occur in column. think code works intended until final line, results in "#name?" filling whole range.

this have far:

dim lastcolumn long dim lastrow long dim blockcolumn long dim blockrange range      'defines lastcolumn, lastrow & blockcolumn     lastcolumn = cells.find(what:="*", after:=range("a1"), lookat:=xlpart, lookin:=xlformulas, _         searchorder:=xlbycolumns, searchdirection:=xlprevious, matchcase:=false).column     lastrow = cells.find(what:="*", after:=range("a1"), lookat:=xlpart, lookin:=xlformulas, _         searchorder:=xlbyrows, searchdirection:=xlprevious, matchcase:=false).row     blockcolumn = cells.find(what:="block", after:=range("a1"), lookat:=xlpart, lookin:=xlformulas, _         searchorder:=xlbycolumns, searchdirection:=xlnext, matchcase:=false).column      'capitalizes text in blockcolumn     set blockrange = range(cells(2, blockcolumn), cells(lastrow, blockcolumn))     blockrange = [upper(blockrange)] 

aside wondering made mistake, i'm sure i've over-complicated this. show me way rethink or simplify it? wondering general pros , cons accomplishing task via looping (as opposed method), not sure if place ask that...

[] shorthand evaluate , not accept variables.

you need use evaluate.

you need index not overwrite entire range first value.

blockrange.value = blockrange.parent.evaluate("index(upper(" & blockrange.address & "),)") 

Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -