+ Reply to Thread
Results 1 to 10 of 10

Macro to select, move to a new location and delete the selected cell

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-24-2012
    Location
    malaysia
    MS-Off Ver
    Excel 2021
    Posts
    114

    Macro to select, move to a new location and delete the selected cell

    Looks simple but 1 step is beyond me. Hope that you can help me.

    Need a macro to select the rows with "Y" from row 5 to row 50, move these rows to another location, delete the original selected rows with "Y".

    See attachment for more infor.

    move comlpeted tasks.jpg

    The step I am having problem with is:
    * how to tell it where to paste the selected rows in unused rows

    Many thanks.

  2. #2
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,879

    Re: Macro to select, move to a new location and delete the selected cell

    So every time the Macro runs, do you want the rows that are already there with Y on the new location to be deleted?

    Or do you want to paste to the next available row?
    Cheers!
    Deep Dave

  3. #3
    Forum Contributor
    Join Date
    10-24-2012
    Location
    malaysia
    MS-Off Ver
    Excel 2021
    Posts
    114

    Re: Macro to select, move to a new location and delete the selected cell

    As per the picture, move the Y rows to a new location, delete the original Y rows.

    I think the picture describes it better than words. Ha.

  4. #4
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,879

    Re: Macro to select, move to a new location and delete the selected cell

    Maybe you did not get my question.

    Assume that the code is being run for the second time, what should happen to the Y rows that were filtered out when the macro was run previously and pasted at a new location.

    Should those be overwritten, or should be kept and new Y rows should be added below?

  5. #5
    Forum Contributor
    Join Date
    10-24-2012
    Location
    malaysia
    MS-Off Ver
    Excel 2021
    Posts
    114

    Re: Macro to select, move to a new location and delete the selected cell

    2 tables

    Table 1 (with yellow header) and Table 2 (the one to the right of Table 1)

    Move the 3 cells row with Y in Table 1 to Table 2. Delete the selected Y row in Table 1.

    Then I should have Table 1 with no row with Y.

    Table 2 should have the old Y rows and newly added Y rows.

    Hope the above is clear now.

  6. #6
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,879

    Re: Macro to select, move to a new location and delete the selected cell

    Try this

    Sub DeleteCopyRowsWithY()
        
        Dim R
        
        Application.ScreenUpdating = False
        
        With Range("A1")
            .AutoFilter Field:=3, Criteria1:="=Y"
            .CurrentRegion.SpecialCells(xlCellTypeVisible).Select
        End With
        
        Selection.Copy Range("E1")
        
        R = Range("E1").CurrentRegion: Range("E1").CurrentRegion.ClearContents
        
        Application.CutCopyMode = False
        
        Rows("2:50").Select: Selection.Delete Shift:=xlUp
        
        Selection.AutoFilter
        
        Range("E1").Resize(UBound(R), 3).Value = R: Range("A1").Activate
        
        Application.ScreenUpdating = True
        
    End Sub
    See the file attached.
    Attached Files Attached Files
    Last edited by NeedForExcel; 04-11-2016 at 02:04 AM.

  7. #7
    Forum Contributor
    Join Date
    10-24-2012
    Location
    malaysia
    MS-Off Ver
    Excel 2021
    Posts
    114

    Re: Macro to select, move to a new location and delete the selected cell

    Many many thanks.

    1 issue. How to move the Y rows to the next unused row in Table 2?

    It is now replacing the used rows. I want to keep the old Y rows in Table 2.

    Thanks.

  8. #8
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,879

    Re: Macro to select, move to a new location and delete the selected cell

    Here!

    Sub DeleteCopyRowsWithY()
        
        Dim R
        
        Application.ScreenUpdating = False
        
        With Range("A1")
            .AutoFilter Field:=3, Criteria1:="=Y"
            .CurrentRegion.Offset(1).SpecialCells(xlCellTypeVisible).Select
        End With
        
        Range("A1:C1").Copy Range("E1")
        
        Selection.Copy Cells(Range("E1").Cells(Rows.Count, 1).End(xlUp).Row + 1, 5)
        
        R = Range("E1").CurrentRegion: Range("E1").CurrentRegion.ClearContents
        
        Application.CutCopyMode = False
        
        Rows("2:50").Select: Selection.Delete Shift:=xlUp
        
        Selection.AutoFilter
        
        Range("E1").Resize(UBound(R), 3).Value = R: Range("A1").Activate
        
        Application.ScreenUpdating = True
        
    End Sub

  9. #9
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,879

    Re: Macro to select, move to a new location and delete the selected cell

    That was exactly what I was asking in Post #2 & #4..

    I will change the code and give you.

  10. #10
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,879

    Re: Macro to select, move to a new location and delete the selected cell

    EDIT: Post Removed By NFE
    Last edited by NeedForExcel; 04-11-2016 at 05:13 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 6
    Last Post: 09-18-2015, 04:19 PM
  2. [SOLVED] Macro to prompt user to select a file and the selected file should saved in location
    By logesh excel in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-26-2015, 03:43 PM
  3. [SOLVED] [Help]macro to open file browser, to select a location, and save the location to a cell
    By zhuleijia in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-06-2013, 09:56 AM
  4. [SOLVED] Need Macro to select and copy data, paste it to a new location, then delete the old row
    By summerela in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 09-25-2012, 05:22 PM
  5. Macro to delete dups and move location
    By ayesha in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 09-17-2009, 03:29 AM
  6. Macro: Select cell A of selected row
    By Pat32 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-04-2009, 08:51 AM
  7. When a drop selected, move row to different location?
    By soltek in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 02-08-2005, 01:04 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1