+ Reply to Thread
Results 1 to 11 of 11

Move rows to new sheet on condition

Hybrid View

  1. #1
    Registered User
    Join Date
    04-20-2010
    Location
    southampton
    MS-Off Ver
    Excel 2003
    Posts
    8

    Move rows to new sheet on condition

    i'm new to this and i am hoping someone can help.

    im trying to re-vamp database managment procedures at work and have got stuck trying to use some functions of visual basic.

    i am trying to move an entire row from a database on 'sheet 1' to the first empty row on 'sheet 2' dependant on column 'B' of 'sheet 1' containing an 'N'.

    this may sound simple enough, but i have spent the last day and a half researching on the net, ironically greatly reducing my current poductivity, and getting nowhere.

    macros thati have tried will move a row but each subsequent row will overwrite each previously moved row. agghhh.

    any help will be greatly appreciated.

  2. #2
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Move rows to new sheet on condition

    Given the lack of details and a sample workbook, perhaps this can be a start for you.

    Option Explicit
    
    Sub MoveRows()
    
        Dim lastrow As Long
        
        lastrow = Sheet2.Cells(Rows.Count, 1).End(xlUp).Row + 1
        
        Application.ScreenUpdating = False
        
        With Sheet1
        
            .Range("A1").CurrentRegion.AutoFilter Field:=2, Criteria1:="=N", Operator:=xlAnd
            .Range("a1").CurrentRegion.Offset(1, 0).SpecialCells(xlCellTypeVisible).Copy Sheet2.Range("A" & lastrow)
            .Range("A1").CurrentRegion.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Delete
            .AutoFilterMode = False
        
        End With
        Application.CutCopyMode = False
        Application.ScreenUpdating = True
    
    End Sub
    See attached.
    Attached Files Attached Files
    Palmetto

    Do you know . . . ?

    You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.

  3. #3
    Registered User
    Join Date
    04-20-2010
    Location
    southampton
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Move rows to new sheet on condition

    thanks for the input will give it a shot.

  4. #4
    Registered User
    Join Date
    04-20-2010
    Location
    southampton
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Move rows to new sheet on condition

    have just tried it and having the following problems:

    macro will not run without being asked to from VBA interface
    initially only sends rows 1-5 to sheet 2 (regardless of what row is given condition N in column 2)
    subsequent transfer attempts only overlay on top of previous data

    might just be being stupid somwhere but would be extremely greatful for any more advice.

    cheers

  5. #5
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Move rows to new sheet on condition

    The code I gave is just a basic approach based on the description in your thread and is, therefore, not tailored to your specific workbook and would have to be modified.

    It would be best if you uploaded a sample workbook that both duplicates the exact structure of your real workbook and contains some data (non-sensitive). We could then tailore the code to the exact needs of your workbook.

  6. #6
    Registered User
    Join Date
    04-20-2010
    Location
    southampton
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Move rows to new sheet on condition

    here is the attached workbook example, hope this works.

    thanking you in advance.

    ammended
    Attached Files Attached Files
    Last edited by mjsmith127; 04-21-2010 at 12:03 PM.

  7. #7
    Registered User
    Join Date
    04-20-2010
    Location
    southampton
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Move rows to new sheet on condition

    thanks for that, your a gentleman.

  8. #8
    Registered User
    Join Date
    04-20-2010
    Location
    southampton
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Move rows to new sheet on condition

    Help!!!!

    I've made some minor adjustments to my workbook and keep losing imformation.

    If anyone can puzzle out my Visual Basic coding I would be most greatful.

    Cheers.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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