excel vba - Move cursor to non-adjacent cell after pasting -
my spreadsheet has several non-adjacent blocks of cells filled in: a3:d4, f3:i7, k3:n7, a9:d10, f9:i13, k9:n13, etc. paste data copied internet each block, 1 after other. once paste 1 block, cursor automatically shift start of next block ready next paste, i.e. f3 when a3:d4 pasted, k3 when f3:i7 pasted, a9 when k3:n7 pasted, etc.
i found , tried macro practice before trying adapt it, not work because not listed in alt-f8 menu. seems close need, in appears "once a1 has value, move cursor c15; once c15 has value, go f9; once f9 has value, go a1".
private sub worksheet_change(byval target excel.range) select case target.address() case "$a$1" range("$c$15").select case "$c$15" range("$f$9").select case "$f$9" range("$a$1").select end select end sub
a "brute force" approach might be:
private sub worksheet_change(byval target excel.range) if not intersect(target, range("a3:d4")) nothing range("f3:i7").select elseif not intersect(target, range("f3:i7")) nothing range("k3:n7").select elseif not intersect(target, range("k3:n7")) nothing range("a9:d10").select elseif not intersect(target, range("a9:d10")) nothing range("f9:i13").select elseif not intersect(target, range("f9:i13")) nothing range("k9:n13").select elseif not intersect(target, range("k9:n13")) nothing range("a3:d4").select end if end sub
assuming have correctly placed code in code-module of worksheet wish code apply to, shouldn't expect macro appear when press alt+f8 marked being private
. will, however, operate whenever change value of 1 of cells in relevant ranges.
as scott beat me answer, decided go 1 better , add "calculation" based approach areas being selected aren't limited 6 mention in question. following code go a3:d4
f3:i7
k3:n7
a9:d10
f9:i13
k9:n13
a15:d16
f15:i19
... ad infinitum.
private sub worksheet_change(byval target excel.range) select case target.column case 1, 2, 3, 4 select case target.row mod 6 case 3, 4 cells(6 * ((target.row - 3) \ 6) + 3, "f").resize(5, 4).select end select case 6, 7, 8, 9 select case target.row mod 6 case 2 case else cells(6 * ((target.row - 3) \ 6) + 3, "k").resize(5, 4).select end select case 11, 12, 13, 14 select case target.row mod 6 case 2 case else cells(6 * ((target.row - 3) \ 6) + 9, "a").resize(2, 4).select end select end select end sub
Comments
Post a Comment