excel - Erase empty cells in an array -
i paste array in column, problem leaves cells in column empty. how can erase cells in column?
this have:
private sub worksheet_change(byval target range) worksheets("info").range("a1").select dim integer dim ilastrow long ilastrow = activesheet.cells(activesheet.rows.count, "a").end(xlup).row dim arrmatrix() string redim arrmatrix(1 ilastrow, 1 1) = 1 ilastrow range("a2").cells(i, 1).select if selection.offset(0, 11) = "pi emitida" arrmatrix(i, 1) = range("a2").cells(i, 1).value end if next worksheets("inicio").range("g4:g1000000").clearcontents worksheets("inicio").range("g4").resize(ubound(arrmatrix, 1)).value = arrmatrix() end sub
there few problems sample code.
- hopefully, on info worksheet's code sheet. should not attempting
.activateworksheetworksheet_changeevent macro. - it isn't clear why need in
worksheet_changeevent macro. as-is, run time value anywhere in worksheet added/modified/deleted. sounds overkill since 2 columns determine outcome columns , l. - the redim statement can used preserve expand array can redimension last rank.
this modification not rely on selecting or activating worksheet(s) before processing them. arrmatrix array expanded needed not end blank values in array.
private sub worksheet_change(byval target range) if not intersect(target, range("a:a, l:l")) nothing on error goto fìn application.enableevents = false dim long, n long dim arrmatrix variant redim arrmatrix(1 1, 1 1) = 2 cells(rows.count, 1).end(xlup).row if cells(i, 12).value = "pi emitida" n = n + 1 redim preserve arrmatrix(1 1, 1 n) arrmatrix(1, n) = cells(i, 1).value end if next worksheets("inicio") .range("g4:g" & rows.count).clearcontents .range("g4").resize(ubound(arrmatrix, 2), 1) = application.transpose(arrmatrix) end end if fìn: application.enableevents = true end sub this run when value in column or column l added/changed/deleted.
since i've been expanding , populating last rank, used application.transpose reorient data before stuffed inicio worksheet.
Comments
Post a Comment