excel - Changing Wide Data back to Long Format - VBA. How to Select Sheet? -
i have been looking wide long format code while , found on here useful. have took , made modifications apply data... works perfectly.
my question though is, add in sheet selection? i.e. want able run macro button on different page. @ moment code works if executed orignal source sheet.
sub wide_to_long() dim rng range, dn range, dta, col integer dim c integer, lastdt integer, lastvis integer lastdt = cells("1", columns.count).end(xltoleft).column set rng = range(range("a2"), range("a" & rows.count).end(xlup)) redim ray(1 rng.count * lastdt, 1 lastdt) each dn in rng lastvis = cells(dn.row, columns.count).end(xltoleft).column col = 8 lastvis c = c + 1 dta = 0 8 select case dta case = 7 ray(c, dta + 1) = cells(1, col) case = 8 ray(c, dta + 1) = dn.offset(, col - 1) case else ray(c, dta + 1) = dn.offset(, dta) end select next dta next col next dn sheets("sheet2").range("a2").resize(c, lastdt).value = ray end sub
there better (if lowpar know make change), found inserting before first dim sheets("").select sheet data rang on worked fine.
Comments
Post a Comment