Excel, VBA and moving rows -


i rookie re: vba , macros (creating or running). need assistance code me copy row 1 spreadsheet another, leaving in original sheet , marking somehow (i think), or otherwise ensuring it's not copied again in future. found few posts moving rows, relied on date entry, not work purpose. sheet has column (h) drop down data validation - entry cell drop down identify row 1 copy next sheet. however, there column follows (j), data entry optional, , don't want row copied before giving user opportunity enter column, it's contents copy (or maybe that's set of separate code?). rows copied new spreadsheet should inserted next available row. thank assistance & instructions can offer.

okay - info. have gathered posts, have following:

sub copyrows() dim xrow integer, xcol integer, lastcol integer dim datavalidation range, rowtocopy integer, copyrange range, destrange range dim copywsrow integer, jcolvalue string dim origws worksheet, copyws worksheet  set origws = activesheet  ' edit these 2 lines needed.  if have "copy" worksheet already, comment out first line ' , change 'sheets("copy")' 'sheets("_____")' worksheets.add(after:=worksheets(1)).name = "copy" set copyws = sheets("copy")  origws.activate  set datavalidation = origws.cells(1, 8) ' cell h1 has data validation.  change necessary rowtocopy = datavalidation.value  'find last column used, isn't col. h.  if it's column h, assume g last column lastcol = origws.cells(1, 1).end(xltoright).column if lastcol = 8 lastcol = lastcol - 1  origws set copyrange = .range(.cells(rowtocopy, 1), .cells(rowtocopy, lastcol)) end  'what's next available row in copy ws? if copyws.usedrange.rows.count = 1 , copyws.cells(1, 1).value = ""     copywsrow = 1 else     copywsrow = copyws.usedrange.rows.count + 1 ' count used rows, , add 1 make next blank row row copy end if 'set destination range  copyws set destrange = .range(.cells(copywsrow, 1), .cells(copywsrow, lastcol)) end  'now, copy info on (technically, set values equal) destrange.value = copyrange.value  'now, check see if column j has info - if so, add line did in copy ws if origws.cells(1, 10).value <> ""     jcolvalue = origws.cells(1, 10).value     copyws.cells(copywsrow, 10).value = jcolvalue end if     ' add note row copied     origws.cells(rowtocopy,13).value = "already copied"      end sub 

a few notes: have assumed right column, data want copy, column g - since h has row value.

also, have h1 cell has data validation - might need edit necessary.

i tested data, in column through g, h1 , j1 being data validation (where outputs number) , j1 "extra" information. if want 'extra info' on each row of data, , not in 1 absolute spot, change jcolvalue formula jcolvalue = origws.cells(rowtocopy,10).value.

and of course, if doesn't work or needs tweaking, let me know.


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -