+ Reply to Thread
Results 1 to 16 of 16

Automatically move rows to another worksheet based on cell value

Hybrid View

  1. #1
    Registered User
    Join Date
    03-05-2013
    Location
    El Paso, Texas
    MS-Off Ver
    Excel 2007
    Posts
    9

    Automatically move rows to another worksheet based on cell value

    Hi,

    I need a macro to automatically move entire rows based on cell value within that row, and automatically delete the empty row that was left behind. I have been looking at other posts, and I haven't been able to successfully figure it out. Please help me! The worksheet from which the data will come is named "Pickup Screen" and the sheet I need it go move to is called "Cost Management." The cell value is called "Delivered" in Column P. Thanks!!

  2. #2
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Automatically move rows to another worksheet based on cell value

    sub movearound()
    
    dim r,r2,rmax,rw
    
    datasheet="Pickup Screen"
    outsheet="Cost Managment"
    
    r2=2
    r=2
    
    while r<= to sheets(datasheet).range("A"&rows.count).end(xlup).row
    if sheets(datasheet).range("P" & r)="Delivered" then
    sheets(datasheet).select
    rows(r & ":" & r).select
    Selection.Copy
     Sheets(outsheet).Select
     Rows(r2 & ":" & r2).Select
     ActiveSheet.Paste
    sheets(datasheet).select
    rows(r & ":" & r).select
    Selection.Delete Shift:=xlUp
    r2=r2+1
    end if
    r=r+1
    wend
    end sub
    Last edited by rcm; 03-31-2013 at 11:03 PM. Reason: missing intructions

  3. #3
    Registered User
    Join Date
    03-05-2013
    Location
    El Paso, Texas
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Automatically move rows to another worksheet based on cell value

    Thank you for replying so quickly! Unfortunately, I got an error message that said "Can't Execute Code in Break Mode." Any idea how to fix it?... Thanks again!

  4. #4
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Automatically move rows to another worksheet based on cell value

    you would have to edit the macro and press the stop button after taking out any breaks in the code.
    if that fails, post a sample with the macro included..

  5. #5
    Registered User
    Join Date
    03-05-2013
    Location
    El Paso, Texas
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Automatically move rows to another worksheet based on cell value

    Unfortunately, I tried to upload the file and I got an error message that the file is too large to for the Forum. Is there some other way for me to get it to you?...

    Thanks!

  6. #6
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Automatically move rows to another worksheet based on cell value

    just send me a portion of it...

  7. #7
    Registered User
    Join Date
    03-05-2013
    Location
    El Paso, Texas
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Automatically move rows to another worksheet based on cell value

    Okay, a worksheet with just the bare bones is attached... Thanks again for your great help on this!
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    03-05-2013
    Location
    El Paso, Texas
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Automatically move rows to another worksheet based on cell value

    Hi RCM,

    Have you had a chance to look at this? I'm DYING here!!! (LOL). If you can, please give me some guidance....

    Thanks!

    Jon

  9. #9
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Automatically move rows to another worksheet based on cell value

    OK I had to clean up a statement in the code provided
    the macro is included and ran in the attached file yet there is no data to be tested on
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    03-05-2013
    Location
    El Paso, Texas
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Automatically move rows to another worksheet based on cell value

    Out of State Pickup Management Tool with Data.xlsm

    Hi RCM,

    I tried the VB code, and unfortunately, it didn't work. I have attached another version with data so we can test it. Again, I can't tell you how much I appreciate the help!...

    Thanks!

    Jon

  11. #11
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Automatically move rows to another worksheet based on cell value

    I tweaked the macro and played with it

  12. #12
    Registered User
    Join Date
    03-05-2013
    Location
    El Paso, Texas
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Automatically move rows to another worksheet based on cell value

    Hi RCM,

    This works great! Thank you!! The only thing I'm still struggling with is how to create the button in the Pickup Screen called "Button 2." I'm trying to copy/paste the macro into my actual file (remember, the actual file was too large to upload). The only thing I don't understand is the button. Can you help my understand how to put the button in my file?...

    Thanks a million, RCM!!

    Jon

  13. #13
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Automatically move rows to another worksheet based on cell value

    OK do you have a DEVELOPER Option? (it should be located to the right of the VIEW option)

    Let's say you do if not (FILE->OPTION->CUSTOMIZE RIBBON-> Check Developer on the Main Tabs)

    Copy the macro into the file

    Select the DEVELOPER option

    Select the insert Option

    Select the little rectable located in the upper right hand corner

    Place it accordingly

    It will ask to assign a macro.

    Select the macro

    Press OK

    OR .... copy your data into the file


    voila!

  14. #14
    Registered User
    Join Date
    03-05-2013
    Location
    El Paso, Texas
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Automatically move rows to another worksheet based on cell value

    RCM, you are a blessing from Heaven!! Everything works!! Now, because of my own stupidity, I realized I created another problem. On the file I sent you, for some reason Columns A ("Called In") and B ("Pieces") are missing from the Cost Management tab. Therefore, when the data is moved over, obviously, it populates the wrong cells. I know I've been a pain in the ***, but can you help me fix this one last thing?...

    Thanks!!

  15. #15
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Automatically move rows to another worksheet based on cell value

    I adjusted the code to copy the record correctly. I highlighted the changed code

    Sub movearound()
    
    Dim r, r2, rmax, rw
    
    datasheet = "Pickup Screen"
    outsheet = "Cost Management"
    
    Application.ScreenUpdating = False
    
    
    r2 = Sheets(outsheet).Range("A" & Rows.Count).End(xlUp).Row + 1
    r = 9
    
    While r <= Sheets(datasheet).Range("A" & Rows.Count).End(xlUp).Row
    If Sheets(datasheet).Range("P" & r) = "Delivered" Then
    
    For c = 1 To 16
    Sheets(outsheet).Cells(r2, c) = Sheets(datasheet).Cells(r, c)
    Next c
    
    Sheets(datasheet).Select
    Rows(r & ":" & r).Select
    Selection.Delete Shift:=xlUp
    r2 = r2 + 1
    r = r - 1
    End If
    r = r + 1
    Wend
    Sheets(datasheet).Select
    Columns("A:Z").AutoFit
    
    Application.ScreenUpdating = True
    
    End Sub

  16. #16
    Registered User
    Join Date
    03-05-2013
    Location
    El Paso, Texas
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Automatically move rows to another worksheet based on cell value

    RCM, you are FANTASTIC!! Thanks so much for your help. Everything works!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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