+ Reply to Thread
Results 1 to 10 of 10

Macro Sort, move, delete

Hybrid View

  1. #1
    Registered User
    Join Date
    08-23-2014
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    20

    Macro Sort, move, delete

    Hey ya all,

    Thanks in advance for any help. I dont know much about writing macros or such but i wonder if someone could help me out. i would like a macro to sort data by date(column A), sort by text(column B), Then search column B for certain text and on match, move that data from column A-E and put that in columns F-J, then remove the data that was in the columns A-E, and continue to do that until it scans all the rows.

    hope that makes sense..

    thanks
    memoe
    Last edited by memoe; 08-25-2014 at 02:28 PM.

  2. #2
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,565

    Re: Macro Sort, move, delete

    There must be better ways but try this on a copy of tour workbook.
    Sub Maybe()
        Dim lr As Long
        lr = Cells(Rows.Count, 1).End(xlUp).Row
        
        Application.ScreenUpdating = False
        
        With Range("A1:E" & lr)
            .Sort Key1:=Range("A1"), Order1:=xlAscending, Key2:=Range("B1") _
                , Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
                  False, Orientation:=xlTopToBottom
            .AutoFilter 2, "certain text"    '<---- Change to text you want
        End With
        
        Range("A2:E" & lr).SpecialCells(12).Copy Range("F2")
        Range("A2:E" & lr).SpecialCells(12).Select
        ActiveSheet.AutoFilterMode = False
        
        Selection.Delete Shift:=(xlUp)
        Range("A1").Select
        
        Application.ScreenUpdating = True
    End Sub

  3. #3
    Registered User
    Join Date
    08-23-2014
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    20

    Re: Macro Sort, move, delete

    thanks for the reply. this works pretty good but one thing it is does wrong is that it is selecting one row of wrong data when moving the information over. one, it is cutting the info from the a-f and pasting all in e-j. I dont want it to cut the cells out and only to paste the values. Also when moving the data over to e-j it take one row of data that should not be removed from a-f and putting it in e-j. the 4th row is where the data starts. i changed the code a bit. not sure if that is what causes the issue for me


    Formula: copy to clipboard
    Sub Maybe()
    Dim lr As Long
    lr = Cells(Rows.Count, 1).End(xlUp).Row

    Application.ScreenUpdating = False

    With Range("A4:E" & lr)
    .Sort Key1:=Range("A4"), Order1:=xlAscending, Key2:=Range("B4") _
    , Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
    False, Orientation:=xlTopToBottom
    .AutoFilter 2, "Sell" '<---- Change to text you want
    End With

    Range("A4:E" & lr).SpecialCells(12).Copy Range("F4")
    Range("A4:E" & lr).SpecialCells(12).Select
    ActiveSheet.AutoFilterMode = False

    Selection.Delete Shift:=(xlUp)
    Range("A4").Select

    Application.ScreenUpdating = True
    End Sub




    thanks memoe

  4. #4
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,565

    Re: Macro Sort, move, delete

    Non of that information was in your first post.
    If you can be a little more specific what is needed, I am sure it can be done.
    An attachment with a before and after would be the best.

  5. #5
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,565

    Re: Macro Sort, move, delete

    Just more or less guessing. Is this it?
    Make sure to try it on a copy of your workbook first.
    Sub Maybe()
        Dim lr As Long
        lr = Cells(Rows.Count, 1).End(xlUp).Row
        
        Application.ScreenUpdating = False
        
        With Range("A3:E" & lr)
            .Sort Key1:=Range("A1"), Order1:=xlAscending, Key2:=Range("B1") _
                , Order2:=xlAscending, Header:=xlYes, OrderCustom:=1, MatchCase:= _
                  False, Orientation:=xlTopToBottom
            .AutoFilter 2, "sell"
        End With
        
        Range("A4:E" & lr).SpecialCells(12).Copy Range("F2")
        ActiveSheet.AutoFilterMode = False
        
        Application.ScreenUpdating = True
    End Sub

  6. #6
    Registered User
    Join Date
    08-23-2014
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    20

    Re: Macro Sort, move, delete

    jolivanes thanks for your replies and help. sorry i thought that once i had some of the basics i could change the macro. Sorry for the guessing game.

    I have the first 3 rows frozen on the file. the data is pasted to A4:E1000 or more, down and the data i want moved is to go into F4:J1000 or more, down. The top 3 rows cannot change. If column B for a row has the word Sell or sell in it then i want A-E (the values only) of that row moved to F-J and then cleared from that row from A-E and so on. Once done all the sells will be listed in F-J and the buys will be listed in A-E and sorted by date which is column A and F

    I hope this is much clearer. sorry i am not able to provide any screenshots and do apologize again for not being clearer.

    thanks again
    memoe
    Last edited by memoe; 08-24-2014 at 05:02 PM.

  7. #7
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,565

    Re: Macro Sort, move, delete

    Sub Maybe()
        Dim lr As Long, sArr
        lr = Cells(Rows.Count, 1).End(xlUp).Row
        sArr = Array("Sell", "sell")
        Application.ScreenUpdating = False
        
        With Range("A3:E" & lr)
            .Sort Key1:=Range("A1"), Order1:=xlAscending, Key2:=Range("B1") _
                , Order2:=xlAscending, Header:=xlYes, OrderCustom:=1, MatchCase:= _
                  False, Orientation:=xlTopToBottom
                    .AutoFilter 2, sArr, xlFilterValues
        End With
        
        Range("A4:E" & lr).SpecialCells(12).Select    'Copy Range("F4")
        ActiveSheet.AutoFilterMode = False
        Selection.Copy Range("F4")
        Selection.Delete Shift:=(xlUp)
        Range("A4").Select
    
        Application.ScreenUpdating = True
    End Sub
    If this is not what you need, take a few minutes and make a small version (=/- 15 rows) of a before and after workbook and attach.
    Last edited by jolivanes; 08-25-2014 at 12:44 AM.

  8. #8
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,565

    Re: Macro Sort, move, delete

    This works on a loop.
    From the way I understand you #6 post, it should do what you have in mind.

    Sub Maybe_A()
        Dim lr1 As Long, lr2 As Long, lr3 As Long, i As Long
        Application.ScreenUpdating = False
        
        lr1 = Cells(Rows.Count, 2).End(xlUp).Row
        For i = lr1 To 4 Step -1
            If Range("B" & i) = "Sell" Or Range("B" & i) = "sell" Then Range("B" & i).Offset(, -1).Resize(, 5).Copy _
               Range("F" & Rows.Count).End(xlUp)(2): Range("B" & i).Offset(, -1).Resize(, 5).Delete Shift:=xlUp
        Next i
        
        lr2 = Cells(Rows.Count, 1).End(xlUp).Row
        With Range("A3:E" & lr2)
            .Sort Key1:=Range("A1"), Order1:=xlAscending, Key2:=Range("B1") _
                , Order2:=xlAscending, Header:=xlYes, OrderCustom:=1, MatchCase:= _
                  False, Orientation:=xlTopToBottom
        End With
        
        lr3 = Cells(Rows.Count, 6).End(xlUp).Row
        With Range("F3:J" & lr3)
            .Sort Key1:=Range("F1"), Order1:=xlAscending, Key2:=Range("G1") _
                , Order2:=xlAscending, Header:=xlYes, OrderCustom:=1, MatchCase:= _
                  False, Orientation:=xlTopToBottom
        End With
        
        Application.ScreenUpdating = True
    End Sub

  9. #9
    Registered User
    Join Date
    08-23-2014
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    20

    Re: Macro Sort, move, delete

    thanks so much for all your time and help with this. It works great!

  10. #10
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,565

    Re: Macro Sort, move, delete

    Glad it does work for you.
    Thanks for letting us know
    Good luck

+ 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. delete and move to next row macro
    By mikguru in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-13-2012, 11:14 AM
  2. Move and Sort Macro
    By SVTF in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-12-2010, 07:21 PM
  3. Using macro to sort and move information
    By oregal in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-03-2008, 09:46 PM
  4. Sort Column, Delete Rows, Delete Column, Move Molumn, more inside?
    By motown in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-13-2008, 09:44 AM
  5. Macro-delete & move heading
    By Nikki in forum Excel General
    Replies: 2
    Last Post: 07-31-2006, 11:23 AM

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