+ Reply to Thread
Results 1 to 4 of 4

Need help with macro to copy/paste a row based on 1 criteria from multi ws to a new ws

Hybrid View

  1. #1
    Registered User
    Join Date
    09-11-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    3

    Need help with macro to copy/paste a row based on 1 criteria from multi ws to a new ws

    i did my own research and i discovered a macro, but it only works for 1 sheet.

    i did look up on for loops to repeat a process but i haven't figured out where to place the code.

    Sub fortonext()
    Dim p As Interger, q As Interger
    p = Worksheets.Count
    For q = 1 To p
    With Worksheets(q)
    
    ' code here....
    
    End With
    Next q
    End Sub
    how would i use this macro if its for more than

    the original code is below:
    Sub SearchForString()
    
        Dim LSearchRow As Integer
        Dim LCopyToRow As Integer
        
        On Error GoTo Err_Execute
        
        'Start search in row 4
        LSearchRow = 4
        
        'Start copying data to row 2 in Sheet2 (row counter variable)
        LCopyToRow = 2
        
        While Len(Range("A" & CStr(LSearchRow)).Value) > 0
            
            'If value in column E = "Mail Box", copy entire row to Sheet2
            If Range("E" & CStr(LSearchRow)).Value = "Mail Box" Then
                
                'Select row in Sheet1 to copy
                Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Select
                Selection.Copy
                
                'Paste row into Sheet2 in next row
                Sheets("Sheet2").Select
                Rows(CStr(LCopyToRow) & ":" & CStr(LCopyToRow)).Select
                ActiveSheet.Paste
                
                'Move counter to next row
                LCopyToRow = LCopyToRow + 1
                
                'Go back to Sheet1 to continue searching
                Sheets("Sheet1").Select
                
            End If
            
            LSearchRow = LSearchRow + 1
            
        Wend
        
        'Position on cell A3
        Application.CutCopyMode = False
        Range("A3").Select
        
        MsgBox "All matching data has been copied."
        
        Exit Sub
        
    Err_Execute:
        MsgBox "An error occurred."
        
    End Sub
    Last edited by exshx; 09-22-2013 at 03:37 PM. Reason: reworking question

  2. #2
    Registered User
    Join Date
    09-11-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Need help with macro to copy/paste a row based on 1 criteria from multi ws to a new ws

    i did some searching and found macros, i edited 1st post

  3. #3
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Need help with macro to copy/paste a row based on 1 criteria from multi ws to a new ws

    Is your question solved or do you still need help?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  4. #4
    Registered User
    Join Date
    09-11-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Need help with macro to copy/paste a row based on 1 criteria from multi ws to a new ws

    no, i just posed code that doe the same function, but iam not experienced enough to merg the code as one, for multiple worksheet in a workbook. with the total worksheets different each day

+ 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] Macro to copy and paste based on criteria to 11 separate sheets
    By msmith7113 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-11-2013, 02:30 AM
  2. [SOLVED] macro to copy/paste based on a criteria
    By winger in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-27-2012, 09:55 AM
  3. Copy Paste cells into a new sheet based on criteria macro
    By Clessie1919 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-19-2012, 02:43 AM
  4. [SOLVED] Macro to copy and paste rows to a new sheet based on criteria
    By Belo in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-31-2010, 02:25 AM
  5. Excel Copy and Paste Macro based on criteria
    By RobbieBobbie23 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-16-2007, 11:38 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