excel vba - Selecting multiple contiguous ranges separately -
i'm designing macro lets users select ranges of dataset check errors (in case, if respondents survey selected same option multiple questions). make easier users see ranges checking (and vba can tell ranges use), color code them so:
set flrange = application.inputbox("select ranges want check flatlining. (to select non-contiguous ranges, hold down ctrl when moving between ranges)", , , , , , , 8) flrange.select flrange.cells.interior.color = rgb(255, 222, 117) i use color determine if range should analyzed:
if cells(1, x).interior.color = rgb(255, 222, 117) however, if users select multiple ranges (that should analyzed separately) right next each other, vba read them part of same range (since have same color).
this best way have figured out allow users input multiple non-contiguous ranges analyzed same method, dont know how solve issue. if has suggestion of how code macro better, appreciate it.
edit: tim , joshua solved this. help!
you can cycle through each range separately , explicitly rather relying on colors differentiate them.
for example:
sub getranges() dim flrange range 'dim v_ranges variant dim integer 'tell code continue if there error on error resume next set flrange = application.inputbox("select ranges want check flatlining. (to select non-contiguous ranges, hold down ctrl when moving between ranges)", , , , , , , 8) 'resume normal error handling on error goto 0 'check ensure range set if flrange nothing exit sub 'loop through separate ranges each rngarea in flrange.areas debug.print rngarea.address next rngarea end sub if run macro , select cells a1:a8 , cells c4:c13, output be:
$a$1:$a$8 $c$4:$c$13 without knowing bit more doing each range, can't dive deeper, keep @ general level now.
i took liberty handle cancel button you. previously, if user selected 'cancel' when inputbox came up, there vba error. accounts error checking ensure range set before proceeding, , if range isn't set code exit subroutine.
Comments
Post a Comment