+ Reply to Thread
Results 1 to 2 of 2

copy entire row to new worksheet if column 2 = "X"

Hybrid View

  1. #1
    Registered User
    Join Date
    12-12-2012
    Location
    lincoln
    MS-Off Ver
    Excel 2003
    Posts
    10

    copy entire row to new worksheet if column 2 = "X"

    hello there, im looking for some help
    Very new excel novice here, but i have a workbook that im contstantly updating and theres lots of entries, but im wanting to copy the various groups listed in column 2 into their own sheet, so its much easier to read and print off by group.
    i know i can auto filter and see this info by column, but a macro that copies the info into its own sheet would be a big help.
    many many thanks for any help.

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

    Re: copy entire row to new worksheet if column 2 = "X"

    Try this code
    Option Explicit
    
    Sub copy_sheet()
    Dim i As Long, lrow As Long
    Dim sname As String
    
    Application.ScreenUpdating = False
    
    With Worksheets("Sheet1")
        lrow = .Range("A" & .Rows.Count).End(xlUp).Row
        For i = 2 To lrow
            sname = .Range("B" & i).Value
            If Not Evaluate("ISREF('" & sname & "'!A1)") Then
                Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = sname
                .Rows("1:1").Copy Worksheets(sname).Range("A1")
            End If
            .Rows(i).Copy Worksheets(sname).Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
        Next i
    End With
    
    MsgBox "Data transfer complete"
    
    Application.ScreenUpdating = True
    
    End Sub
    Copy the Excel VBA code
    Select the workbook in which you want to store the Excel VBA code
    Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
    Choose Insert | Module
    Where the cursor is flashing, choose Edit | Paste

    To run the Excel VBA code:
    Choose Tools | Macro | Macros
    Select a macro in the list, and click the Run button
    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]

+ 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