Home

Excel 2010 VBA to Move rows in a sheet based on the project Status

%3CLINGO-SUB%20id%3D%22lingo-sub-501108%22%20slang%3D%22en-US%22%3EExcel%202010%20VBA%20to%20Move%20rows%20in%20a%20sheet%20based%20on%20the%20project%20Status%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-501108%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20found%20so%20many%20different%20codes%20for%20this%20it's%20ridiculous.%20I%20don't%20think%20it%20should%20be%20very%20complicated.%20I%20want%20to%20move%20an%20entire%20row%20of%20data%20in%20sheet%201%20based%20on%20the%20status%20of%20column%20%22C%22%20in%20that%20row%2C%20in%20sheet%201%20%2C%26nbsp%3B%20to%20sheet%202.%20I%20want%20the%20rows%20in%20sheet%202%20to%20be%20a%20running%20list-%20IE%20not%20keep%20overwriting.%20Can%20someone%20please%20help%20me%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-501108%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-502307%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%202010%20VBA%20to%20Move%20rows%20in%20a%20sheet%20based%20on%20the%20project%20Status%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-502307%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F329914%22%20target%3D%22_blank%22%3E%40neilbicknell%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EApologies%20this%20code%20is%20a%20bit%20rough%2C%20I'm%20not%20a%20fan%20of%20hardcoding%20cell%20references%20and%20counters%20but%20hopefully%20this%20gives%20you%20an%20idea%20and%20you%20can%20tweak%20it%20to%20suit%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3ESub%20MoveToSheet2()%0A%0A%0ADim%20i%20As%20Integer%0A%0ADim%20RowToRemove%20As%20Range%0A%0A%0AFor%20i%20%3D%201%20To%201000%0A%0A%20%20%20%20Sheet1.Range(%22C1%22).Offset(i%2C%200).Select%0A%0A%20%20%20%20If%20Selection.Value%20%3D%20%22move%22%20Then%0A%20%20%20%20%0A%20%20%20%20%20%20%20Set%20RowToRemove%20%3D%20Selection%0A%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20Sheet2.Range(%22A1%22).EntireRow.Insert%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20Selection.EntireRow.Copy%20Sheet2.Range(%22A1%22)%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20RowToRemove.EntireRow.Delete%0A%20%20%20%20%0A%20%20%20%20%20%20%20%20i%20%3D%20i%20-%201%0A%0A%0A%20%20%20%20End%20If%0A%0ANext%20i%0A%0A%0A%0A%0AEnd%20Sub%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-505116%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%202010%20VBA%20to%20Move%20rows%20in%20a%20sheet%20based%20on%20the%20project%20Status%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-505116%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F9832%22%20target%3D%22_blank%22%3E%40Wyn%20Hopkins%3C%2FA%3E%26nbsp%3Bthank%20you%20but%20that%20code%20didn't%20do%20anything.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20need%20rows%202%2C%204%20and%205%20to%20move%20to%20sheet%202%20based%20on%20the%20Status%20of%20%22new%22%20being%20selected.%20This%20will%20be%20selected%20by%20a%20drop%20down%20box%20list%20of%20data.%20please%20help%20as%20I%20don't%20really%20know%20anything%20about%20coding%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CTABLE%20border%3D%220%22%20cellspacing%3D%220%22%20cellpadding%3D%220%22%3E%3CTBODY%3E%3CTR%3E%3CTD%3EDate%3C%2FTD%3E%3CTD%3EName%3C%2FTD%3E%3CTD%3EStatus%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E10-Jan%3C%2FTD%3E%3CTD%3EBob%3C%2FTD%3E%3CTD%3ENew%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E10-Feb%3C%2FTD%3E%3CTD%3ESue%3C%2FTD%3E%3CTD%3EClosed%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E12-Feb%3C%2FTD%3E%3CTD%3EJan%3C%2FTD%3E%3CTD%3ENew%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E13-Dec%3C%2FTD%3E%3CTD%3EFrank%3C%2FTD%3E%3CTD%3ENew%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3E%26nbsp%3B%3C%2FTD%3E%3CTD%3E%26nbs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US%22%3ERe%3A%20Excel%202010%20VBA%20to%20Move%20rows%20in%20a%20sheet%20based%20on%20the%20project%20Status%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-506595%22%20slang%3D%22en-US%22%3EAh%20Ok%2C%20so%20in%20the%20code%20you%20need%20to%20change%20the%20word%20%22move%22%20to%20%22New%22%20%3CBR%20%2F%3E%3CBR%20%2F%3EAlso%20the%20i%20%3D%201%20to%201000%20means%20the%20code%20will%20run%20for%201%2C000%20rows.%20Increase%20or%20decrease%20this%20number%20as%20required.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20would%20really%20warn%20against%20using%20VBA%20code%20if%20you%20are%20not%20very%20familiar%20with%20it%20as%20it%20can%20lead%20to%20unintended%20errors.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-506599%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%202010%20VBA%20to%20Move%20rows%20in%20a%20sheet%20based%20on%20the%20project%20Status%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-506599%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F9832%22%20target%3D%22_blank%22%3E%40Wyn%20Hopkins%3C%2FA%3E%26nbsp%3Byes%20I%20understood%20that%20much.%20I%20enter%20this%20code%20on%20sheet%201%20and%20it%20does%20not%20do%20anything%2C%20having%20changed%20move%20to%20%22New%22%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-506601%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%202010%20VBA%20to%20Move%20rows%20in%20a%20sheet%20based%20on%20the%20project%20Status%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-506601%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F9832%22%20target%3D%22_blank%22%3E%40Wyn%20Hopkins%3C%2FA%3E%26nbsp%3Byes%20i%20understood%20this.%20The%20code%20did%20not%20work%3A(%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-506618%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%202010%20VBA%20to%20Move%20rows%20in%20a%20sheet%20based%20on%20the%20project%20Status%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-506618%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F329914%22%20target%3D%22_blank%22%3E%40neilbicknell%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECould%20you%20send%20me%20a%20screenshot%20like%20this%20one%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20823px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F111248i612F7B9AECE09DDC%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22image.png%22%20title%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-508400%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%202010%20VBA%20to%20Move%20rows%20in%20a%20sheet%20based%20on%20the%20project%20Status%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-508400%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F9832%22%20target%3D%22_blank%22%3E%40Wyn%20Hopkins%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20844px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F111373iEFADE1139AB9B26A%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Capture.PNG%22%20title%3D%22Capture.PNG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-508417%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%202010%20VBA%20to%20Move%20rows%20in%20a%20sheet%20based%20on%20the%20project%20Status%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-508417%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F9832%22%20target%3D%22_blank%22%3E%40Wyn%20Hopkins%3C%2FA%3E%26nbsp%3Bappreciate%20your%20help!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-509692%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%202010%20VBA%20to%20Move%20rows%20in%20a%20sheet%20based%20on%20the%20project%20Status%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-509692%22%20slang%3D%22en-US%22%3ESo%20when%20you%20run%20that%20code%20nothing%20happens%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-509999%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%202010%20VBA%20to%20Move%20rows%20in%20a%20sheet%20based%20on%20the%20project%20Status%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-509999%22%20slang%3D%22en-US%22%3EThat%E2%80%99s%20correct.%20Does%20the%20code%20work%20for%20you%3F%20Could%20the%20fact%20that%20I%20am%20running%202010%20be%20a%20problem%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-510183%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%202010%20VBA%20to%20Move%20rows%20in%20a%20sheet%20based%20on%20the%20project%20Status%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-510183%22%20slang%3D%22en-US%22%3EWorks%20for%20me%2C%20should%20work%20on%202010%3CBR%20%2F%3E%3CBR%20%2F%3EMake%20sure%20that%20%22New%22%20doesn't%20contain%20spaces%20at%20the%20start%20or%20end%20in%20column%20C%20of%20sheet%201%3CBR%20%2F%3E%3CBR%20%2F%3EIf%20you%20can%20attach%20a%20de-sensitised%20version%20of%20your%20file%20I'll%20take%20a%20look%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-515323%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%202010%20VBA%20to%20Move%20rows%20in%20a%20sheet%20based%20on%20the%20project%20Status%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-515323%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F9832%22%20target%3D%22_blank%22%3E%40Wyn%20Hopkins%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-520660%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%202010%20VBA%20to%20Move%20rows%20in%20a%20sheet%20based%20on%20the%20project%20Status%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-520660%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F329914%22%20target%3D%22_blank%22%3E%40neilbicknell%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThat%20works%20for%20me%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI've%20added%20a%20button%20to%20run%20the%20code.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-550188%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%202010%20VBA%20to%20Move%20rows%20in%20a%20sheet%20based%20on%20the%20project%20Status%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-550188%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F9832%22%20target%3D%22_blank%22%3E%40Wyn%20Hopkins%3C%2FA%3E%26nbsp%3Bugh%20I%20don't%20understand%20why%20the%20code%20doesn't%20work%20for%20me.%20Having%20the%20button%20works%20but%20I%20would%20rather%20not%20have%20to%20have%20the%20user%20press%20this.%20I%20would%20like%20the%20rows%20to%20automatically%20move%20based%20on%20their%20selection.%20Any%20other%20thoughts%20as%20to%20why%20it%20isn't%20working%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-550459%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%202010%20VBA%20to%20Move%20rows%20in%20a%20sheet%20based%20on%20the%20project%20Status%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-550459%22%20slang%3D%22en-US%22%3EHi%3CBR%20%2F%3EThe%20code%20only%20works%20for%20me%20when%20I%20%E2%80%9Crun%E2%80%9D%20it%20manually.%3CBR%20%2F%3E%3CBR%20%2F%3EWhat%20is%20the%20trigger%20%2F%20event%20you%20want%20to%20make%20the%20code%20run%3F%20You%20mention%20you%20want%20the%20rows%20to%20move%20%E2%80%9Cbased%20on%20their%20selection%E2%80%9D.%20Can%20you%20explain%20what%20you%20mean%3CBR%20%2F%3EThanks%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-550776%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%202010%20VBA%20to%20Move%20rows%20in%20a%20sheet%20based%20on%20the%20project%20Status%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-550776%22%20slang%3D%22en-US%22%3EAs%20soon%20as%20%E2%80%9CNew%E2%80%9D%20is%20entered%20in%20column%20C%2C%20I%20want%20that%20row%20to%20move%20automatically%20to%20sheet%202.%20Thus%20disappearing%20from%20sheet%201%20immediately%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-550958%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%202010%20VBA%20to%20Move%20rows%20in%20a%20sheet%20based%20on%20the%20project%20Status%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-550958%22%20slang%3D%22en-US%22%3EAh%2C%20OK%2C%20that%20requires%20some%20more%20code.%20I'll%20get%20back%20to%20you%20after%20work%20tonight.%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-552367%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%202010%20VBA%20to%20Move%20rows%20in%20a%20sheet%20based%20on%20the%20project%20Status%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-552367%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F329914%22%20target%3D%22_blank%22%3E%40neilbicknell%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFirst%20step%20is%20to%20name%20column%20C%20as%20StatusColumn%20in%20the%20name%20manager%20box%26nbsp%3B%20(this%20avoids%20you%20code%20breaking%20should%20someone%20insert%20a%20column%20to%20the%20left%20in%20the%20future)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20356px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F112735i2F067225E15D729B%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22image.png%22%20title%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThen%20put%20this%20code%20in%20your%20sheet1%20VBA%20window%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3EPrivate%20Sub%20Worksheet_SelectionChange(ByVal%20Target%20As%20Range)%0A%0ADim%20RowToRemove%20As%20Range%0A%0A'avoid%20triggering%20code%20if%20New%20is%20typed%20in%20any%20other%20random%20cell%20expect%20for%20inside%20the%20StatusColumn%0A%0AIf%20Intersect(Target%2C%20Range(%22StatusColumn%22))%20Is%20Nothing%20Then%0A%20%20%20%20Exit%20Sub%0AEnd%20If%0A%0A%0A%0A'avoid%20error%20if%20entire%20column%20is%20selected%0AIf%20Target.Rows.Count%20%26gt%3B%201%20Then%0A%20%20%20%20Exit%20Sub%0AEnd%20If%0A%0A%0A'Relies%20on%20the%20idea%20that%20user%20will%20press%20Enter%20after%20typing%20%22New%22%20which%20shifts%20the%20cursor%20down%0A'and%20therefore%20the%20row%20above%20(offset%20-1)%20is%20the%20one%20to%20remove%0A%0A%0AIf%20Target.Offset(-1%2C%200).Value%20%3D%20%22New%22%20Then%0A%0A%20%20%20%20Set%20RowToRemove%20%3D%20Selection.Offset(-1%2C%200)%0A%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20Sheet2.Range(%22A1%22).EntireRow.Insert%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20RowToRemove.EntireRow.Copy%20Sheet2.Range(%22A1%22)%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20RowToRemove.EntireRow.Delete%0A%20%20%20%20%0A%20%20%20%20Set%20RowToRemove%20%3D%20Nothing%0A%0A%0AEnd%20If%0A%0AEnd%20Sub%0A%3C%2FPRE%3E%0A%3CP%3EThis%20code%20does%20assume%20that%20the%20user%20will%20type%20New%20and%20press%20Enter%20to%20move%20the%20cursor%20down%20to%20the%20next%20cell.%26nbsp%3B%20Some%20users%20do%20change%20that%20Enter%20behaviour%20to%20jump%20right%20instead%20of%20down%20which%20will%20result%20in%20the%20wrong%20row%20being%20moved.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWith%20time%20I'd%20investigate%20a%20more%20robust%20solution%20but%20this%20is%20the%20best%20I%20can%20do%20for%20now.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHope%20it%20helps%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWyn%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
neilbicknell
Occasional Contributor

I have found so many different codes for this it's ridiculous. I don't think it should be very complicated. I want to move an entire row of data in sheet 1 based on the status of column "C" in that row, in sheet 1 ,  to sheet 2. I want the rows in sheet 2 to be a running list- IE not keep overwriting. Can someone please help me?

18 Replies

Hi @neilbicknell 

 

Apologies this code is a bit rough, I'm not a fan of hardcoding cell references and counters but hopefully this gives you an idea and you can tweak it to suit 

 

Sub MoveToSheet2()


Dim i As Integer

Dim RowToRemove As Range


For i = 1 To 1000

    Sheet1.Range("C1").Offset(i, 0).Select

    If Selection.Value = "move" Then
    
       Set RowToRemove = Selection
       
       Sheet2.Range("A1").EntireRow.Insert
        
       Selection.EntireRow.Copy Sheet2.Range("A1")
        
       RowToRemove.EntireRow.Delete
    
        i = i - 1


    End If

Next i




End Sub

@Wyn Hopkins thank you but that code didn't do anything.

 

I need rows 2, 4 and 5 to move to sheet 2 based on the Status of "new" being selected. This will be selected by a drop down box list of data. please help as I don't really know anything about coding

 

 

DateNameStatus  
10-JanBobNew  
10-FebSueClosed  
12-FebJanNew  
13-DecFrankNew  
     
     
     
     
     
     
     
     
    DATA
    New
    Closed
    Dead
     
Ah Ok, so in the code you need to change the word "move" to "New"

Also the i = 1 to 1000 means the code will run for 1,000 rows. Increase or decrease this number as required.

I would really warn against using VBA code if you are not very familiar with it as it can lead to unintended errors.

@Wyn Hopkins yes I understood that much. I enter this code on sheet 1 and it does not do anything, having changed move to "New"

@Wyn Hopkins yes i understood this. The code did not work:(

@neilbicknell 

 

Could you send me a screenshot like this one

 

image.png

So when you run that code nothing happens?
That’s correct. Does the code work for you? Could the fact that I am running 2010 be a problem?
Works for me, should work on 2010

Make sure that "New" doesn't contain spaces at the start or end in column C of sheet 1

If you can attach a de-sensitised version of your file I'll take a look

@neilbicknell 

 

That works for me

 

I've added a button to run the code.

 

 

@Wyn Hopkins ugh I don't understand why the code doesn't work for me. Having the button works but I would rather not have to have the user press this. I would like the rows to automatically move based on their selection. Any other thoughts as to why it isn't working?

Hi
The code only works for me when I “run” it manually.

What is the trigger / event you want to make the code run? You mention you want the rows to move “based on their selection”. Can you explain what you mean
Thanks
As soon as “New” is entered in column C, I want that row to move automatically to sheet 2. Thus disappearing from sheet 1 immediately
Ah, OK, that requires some more code. I'll get back to you after work tonight.

 

@neilbicknell 

 

First step is to name column C as StatusColumn in the name manager box  (this avoids you code breaking should someone insert a column to the left in the future)

 

image.png

 

 

Then put this code in your sheet1 VBA window 

 

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim RowToRemove As Range

'avoid triggering code if New is typed in any other random cell expect for inside the StatusColumn

If Intersect(Target, Range("StatusColumn")) Is Nothing Then
    Exit Sub
End If



'avoid error if entire column is selected
If Target.Rows.Count > 1 Then
    Exit Sub
End If


'Relies on the idea that user will press Enter after typing "New" which shifts the cursor down
'and therefore the row above (offset -1) is the one to remove


If Target.Offset(-1, 0).Value = "New" Then

    Set RowToRemove = Selection.Offset(-1, 0)
       
       Sheet2.Range("A1").EntireRow.Insert
        
       RowToRemove.EntireRow.Copy Sheet2.Range("A1")
        
    RowToRemove.EntireRow.Delete
    
    Set RowToRemove = Nothing


End If

End Sub

This code does assume that the user will type New and press Enter to move the cursor down to the next cell.  Some users do change that Enter behaviour to jump right instead of down which will result in the wrong row being moved.

 

With time I'd investigate a more robust solution but this is the best I can do for now.

 

Hope it helps

 

Wyn