excel vba - VBA code to select the first visible column in a dynamic range -
i couldn't find exact answer query. need code access first unhidden column in range..the columns hidden or unhidden dynamically , each time code has select first column in unhidden range..any thoughts?
my current attempt:
private sub test1_click() application.enablecancelkey = xldisabled on error resume next dim answer string 'activesheet.unprotect "" dim rw range each rw in sheet1.range("$c$30:$e$39") if sheet1.range("b27").text <> "" or sheet1.range("b30:b39").text <> "" rw.formula = rw.offset(0, -1).value * sheet1.range("b27").value + rw.offset(0, -1).value else answer = msgbox("eh!!! there no data copy..please fill first column , try again", vbokonly, "alert") exit sub end if next rw 'activesheet.protect "" end sub
given arbitrary range like:
range("c3:h13")
and want select first un-hidden column in range then:
sub selectfirstvisiblecolumn() dim r range set r = range("c3:h13") nlastrow = r.rows.count + r.row - 1 nlastcolumn = r.columns.count + r.column - 1 nfirstrow = r.row nfirstcolumn = r.column = nfirstcolumn nlastcolumn if cells(1, i).entirecolumn.hidden = false cells(1, i).entirecolumn.select exit sub end if next end sub
and if wanted limit selection cells in range rather entire column then:
sub selectfirstvisiblecolumn() dim r range set r = range("c3:h13") nlastrow = r.rows.count + r.row - 1 nlastcolumn = r.columns.count + r.column - 1 nfirstrow = r.row nfirstcolumn = r.column = nfirstcolumn nlastcolumn if cells(1, i).entirecolumn.hidden = false intersect(r, cells(1, i).entirecolumn).select exit sub end if next end sub
for example:
Comments
Post a Comment