Copy Cell Contents - Excel 2010 VBA -
i trying accomplish relatively (i think) simple task. want create button copies contents of active cell clipboard. use crtl+v paste application. goal copy string of text inside of excel sheet... including formatting , line breaks. want avoid having press f2, crtl+shift+home, crtl+c. there way this?
plain old crtl+c , activecell.copy not achieve right result because rid of line breaks when pasting app. tia
how this. it's character character approach :
sub copycellcontents() 'divides original cell multiple, delimiter line break (character 10) 'copies individual character text , formatting 'copies result clipboard dim wssrc worksheet 'sheet original cells, ones want copy dim wstemp worksheet 'sheet temporatily stored data, cells here in clipboard dim intorigchars integer 'count of characters in original cell dim intdestchars integer 'count of characters in destination cell (varies rows) set wssrc = worksheets("format") 'change suit set wstemp = worksheets("temp") 'change suit, create new sheet, purpose of temporarily storing contents of cell wssrc intdestchars = 1 'loop through characters in original cell; change ".cells(1, 1)" suit - use rename tool change of them below intorigchars = 1 .cells(1, 1).characters.count 'if character line break (character 10), move next row , reset destination characters 1 if asc(.cells(1, 1).characters(intorigchars, 1).text) = 10 rowadd = rowadd + 1 intdestchars = 1 else 'copy text , formatting temporary cells wstemp.cells(1 + rowadd, 1).characters(intdestchars, 1) .text = wssrc.cells(1, 1).characters(intorigchars, 1).text .font .bold = wssrc.cells(1, 1).characters(intorigchars, 1).font.bold .color = wssrc.cells(1, 1).characters(intorigchars, 1).font.color .italic = wssrc.cells(1, 1).characters(intorigchars, 1).font.italic .underline = wssrc.cells(1, 1).characters(intorigchars, 1).font.underline .fontstyle = wssrc.cells(1, 1).characters(intorigchars, 1).font.fontstyle end end intdestchars = intdestchars + 1 end if next end 'wssrc 'put result cells clipboard wstemp .range(.cells(1, 1), .cells(rowadd + 1, 1)).copy end end sub
Comments
Post a Comment