+ Reply to Thread
Results 1 to 7 of 7

Move Complete Rows to bottom of Worksheet

Hybrid View

  1. #1
    Registered User
    Join Date
    02-22-2019
    Location
    Michigan, USA
    MS-Off Ver
    MS 2010
    Posts
    49

    Move Complete Rows to bottom of Worksheet

    Hello All,

    I have created a VBA worksheet that is populated by 2 userforms. The "add new shop order" userform populates the SOL tab and the "Look up shop order" populates the Tool_Room tab and also the SOL tab. All the data is entered using the two userforms. On the Tool_Room worksheet I would like for all the rows with a "Date Complete" entered to be moved to the bottom. For example if someone uses the "Look Up Shop Order" userform and enters a "Date Complete" and saves the information. I would like that row to be moved to the bottom of the Tool_Room worksheet only. I have attempted a few codes and managed to have the code do it manually but I would like it to happen automatically whenever someone enters a "Date Complete". I have attached a copy of my workbook, the password to unlock the sheets is (pass: abc) and the password to save the "look up shop order" is (pass: Secret). Thank you so much for your assistance I am absolutely stuck.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Move Complete Rows to bottom of Worksheet

    Change the End of your Save Macro to:=


    With Sheets("Tool_Room")
    LR = .Cells(Rows.Count, 1).End(xlUp).Row + 1
        .Rows(frng.Row).Cut
        .Range("A" & LR).Insert Shift:=xlDown
    End With
    
    ThisWorkbook.Sheets("SOL").Protect Password:="abc" 'Protects worksheet again'
    ThisWorkbook.Sheets("Tool_Room").Protect Password:="abc"
    
    ThisWorkbook.Save
    
    End Sub
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Registered User
    Join Date
    02-22-2019
    Location
    Michigan, USA
    MS-Off Ver
    MS 2010
    Posts
    49

    Re: Move Complete Rows to bottom of Worksheet

    This is does what I needed I am very thankful. I was wondering if it is possible for the rows to be entered sequentially. Meaning all the shop orders with a date complete entered are in order by shop number from least to greatest. For example if shop orders 4 and 6 both have date completed when I enter a date completed for shop order 5 for it to be moved in between row 4 and 6. Also when a new shop order is entered I want the new row to be at the bottom of the shop orders with no date complete but above the shop orders with a date complete. I am new to VBA and dont know the command string to add to UserForm1 to make this possible.
    Last edited by Likayuu19; 12-16-2019 at 02:27 PM.

  4. #4
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Move Complete Rows to bottom of Worksheet

    Easily done.

    Move the Row to the bottom as we already have.

    Then Find the first date in column H.

    Then Sort from that row to the bottom by column A.


    Change the end of your code to:


    
    
    If Not frng Is Nothing Then
        With Me
            frng.Offset(, 2) = .ToolNumber_TB2
            frng.Offset(, 3) = .ToolMake1_CB
            frng.Offset(, 4) = .Hours1_TB2
            frng.Offset(, 5) = .ToolMake2_CB
            frng.Offset(, 6) = .Hours2_TB2
            frng.Offset(, 7) = .Complete_TB2
            frng.Offset(, 8) = .ToolingC_TB
            frng.Offset(, 9) = .CostM_TB
        End With
    End If
    
    With Sheets("Tool_Room")
    LR = .Cells(Rows.Count, 1).End(xlUp).Row + 1
        .Rows(frng.Row).Cut
        .Range("A" & LR).Insert Shift:=xlDown
        
    SR = .Range("H" & LR).End(xlUp).Row
    
    SortRange = Range("A" & SR & ":K" & LR).Address
    
        ActiveWorkbook.Worksheets("Tool_Room").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Tool_Room").Sort.SortFields.Add2 Key:=Range("A" & SR & ":A" & LR) _
            , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("Tool_Room").Sort
            .SetRange Range(SortRange)
            .Header = xlGuess
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
    
    End With
    
    ThisWorkbook.Sheets("SOL").Protect Password:="abc" 'Protects worksheet again'
    ThisWorkbook.Sheets("Tool_Room").Protect Password:="abc"
    
    ThisWorkbook.Save
    
    End Sub
    Last edited by mehmetcik; 12-16-2019 at 08:26 PM.

  5. #5
    Registered User
    Join Date
    02-22-2019
    Location
    Michigan, USA
    MS-Off Ver
    MS 2010
    Posts
    49

    Re: Move Complete Rows to bottom of Worksheet

    I tried the code but I don't see a change. I input the code into the Userform2 save change command. I have attached the updated worksheet with the implemented code. Also what should I change in the userform1 to be able to add a new entry on top of the date completed.
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Move Complete Rows to bottom of Worksheet

    Try this code:

    
    Private Sub SaveCh_CB_Click() 'Unprotects worksheets and saves informations back into database'
     
    ThisWorkbook.Sheets("SOL").Unprotect Password:="abc"
    ThisWorkbook.Sheets("Tool_Room").Unprotect Password:="abc"
     
    Const strPass  As String = "Secret" 'Password to make changes in userform'
    Dim strPassCheck As String
    Dim lPassAttempts As Long, lCount As Long
    
    Do Until lPassAttempts = 3
        lPassAttempts = 1 + lPassAttempts
            lCount = lCount + 1
            strPassCheck = InputBox("Password?", "Attempt " & lPassAttempts & " of 3")
        If strPassCheck = vbNullString Or lPassAttempts = 3 Then Exit Sub
        If strPassCheck = strPass Then Exit Do
    Loop
    
    MsgBox "Success"
     
     Dim findString As String, toolString As String
        Dim fndrng As Range, frng As Range
        
    findString = Me.Shop_TB2.Value
    
    Set fndrng = Sheets("SOL").Range("A:A").Find(What:=findString, LookIn:=xlValues, _
        LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
    
    If Not fndrng Is Nothing Then
        With Me
            fndrng.Offset(, 1) = .Date_TB2
            fndrng.Offset(, 2) = .Name_TB2
            fndrng.Offset(, 3) = .Area_CB2
            fndrng.Offset(, 4) = .Account_TB2
            fndrng.Offset(, 5) = .PartNum_TB2
            fndrng.Offset(, 6) = .PartName_TB2
            fndrng.Offset(, 7) = .Quantity_TB2
            fndrng.Offset(, 8) = .RequestedDate_TB2
            fndrng.Offset(, 9) = .Complete_TB2
            fndrng.Offset(, 10) = .Build_TB2
        End With
    End If
        
    toolString = Me.Shop_TB2.Value
    
    Set frng = Sheets("Tool_Room").Range("A:A").Find(What:=toolString, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
    
    If Not frng Is Nothing Then
        With Me
            frng.Offset(, 2) = .ToolNumber_TB2
            frng.Offset(, 3) = .ToolMake1_CB
            frng.Offset(, 4) = .Hours1_TB2
            frng.Offset(, 5) = .ToolMake2_CB
            frng.Offset(, 6) = .Hours2_TB2
            frng.Offset(, 7) = .Complete_TB2
            frng.Offset(, 8) = .ToolingC_TB
            frng.Offset(, 9) = .CostM_TB
        End With
    End If
    
    With Sheets("Tool_Room")
    
    LR = .Cells(Rows.Count, 1).End(xlUp).Row + 1
    '    .Rows(frng.Row).Cut
    '    .Range("A" & LR).Insert Shift:=xlDown
        
        .Range("H12").Value = ""
        ActiveWorkbook.Worksheets("Tool_Room").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Tool_Room").Sort.SortFields.Add2 Key:=Range( _
            "H8:H" & LR), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
            xlSortTextAsNumbers
        With ActiveWorkbook.Worksheets("Tool_Room").Sort
            .SetRange Range("A8:J" & LR)
            .Header = xlGuess
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        
    
    SR = .Range("H" & LR).End(xlUp).Row
    
        .Rows(SR + 1 & ":" & LR).Cut
        .Range("A8").Insert Shift:=xlDown
    
    SR = LR - SR + 7
    
        ActiveWorkbook.Worksheets("Tool_Room").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Tool_Room").Sort.SortFields.Add2 Key:=Range( _
            "A8:A" & SR), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
            xlSortTextAsNumbers
        With ActiveWorkbook.Worksheets("Tool_Room").Sort
            .SetRange Range("A8:J" & SR)
            .Header = xlGuess
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        
            ActiveWorkbook.Worksheets("Tool_Room").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Tool_Room").Sort.SortFields.Add2 Key:=Range( _
            "A" & SR + 1 & ":A" & LR), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
            xlSortTextAsNumbers
        With ActiveWorkbook.Worksheets("Tool_Room").Sort
            .SetRange Range("A" & SR + 1 & ":J" & LR)
            .Header = xlGuess
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        
    End With
    
    
    ThisWorkbook.Sheets("SOL").Protect Password:="abc" 'Protects worksheet again'
    ThisWorkbook.Sheets("Tool_Room").Protect Password:="abc"
    
    ThisWorkbook.Save
    
    End Sub
    Last edited by mehmetcik; 12-17-2019 at 07:08 PM.

  7. #7
    Registered User
    Join Date
    02-22-2019
    Location
    Michigan, USA
    MS-Off Ver
    MS 2010
    Posts
    49

    Re: Move Complete Rows to bottom of Worksheet

    This works great I would just like to delete the empty rows that appear after the update. I am using
    Range("A1").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    . Not quite sure where to insert this code for it to work.

+ 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. [SOLVED] Move Row to Bottom of 2nd worksheet then delete from sheet 1
    By mlcollins in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-13-2018, 02:57 AM
  2. [SOLVED] Need to move row to bottom of another worksheet based on cell criteria
    By amymsellers in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 03-30-2016, 09:49 PM
  3. [SOLVED] Move all rows where cell = "complete" to the bottom of the list
    By floribunda in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-15-2013, 03:25 PM
  4. [SOLVED] Macro to move complete row from one worksheet to another
    By Kimston in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-10-2012, 11:01 AM
  5. move to bottom of worksheet
    By jmhultin in forum Excel General
    Replies: 3
    Last Post: 08-17-2008, 08:11 PM
  6. How can I take specific rows and move them to the bottom
    By Mcobra41 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-28-2005, 01:06 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