+ Reply to Thread
Results 1 to 1 of 1

Macro To Sort Data From 2 Columns and Copy to New Worksheet

  1. #1
    Registered User
    Join Date
    08-29-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    1

    Macro To Sort Data From 2 Columns and Copy to New Worksheet

    I am new here and have only limited experience with Excel. I have an Excel worksheet that lists cables with the equipment name at the "A" end of the cables in column 2 and the equipment name at the "B" end of the cables in column 7. I am looking to build a macro to search through column 2 then column 7 for a specified equipment name and then copy the rows of data to a new worksheet. I have been successful in building a macro that searches through one column and copies the data to the next sheet but I have not been able to get the macro to go through both columns to extract the data. I have tried everything that I have been able to find on line thus far with no luck. I am using Excel 2010 and the following is the macro that I am presently using.

    Private Sub Worksheet Change(ByVal Target As Range)
    Dim rng1 As Range
    Dim ws1 As Worksheet
    Dim ws2 As Worksheet
    Dim ws3 As Worksheet
    Set rng1 = Intersect([A:A], Target)
    If rng1 Is Nothing Then Exit Sub
    Set ws1 = Sheets(2)
    Set ws2 = Sheets(3)
    Set ws3 = Sheets(4)
    ws1.[A:H].ClearContents
    ws2.[A:H].ClearContents
    ws3.[A:H].ClearContents
    Application.ScreenUpdating = False
    ActiveSheet.AutoFilterMode = False
    With ActiveSheet.Range("A1:H500")
    .AutoFilter Field:=7, Criteria1:="Rack #1"
    .Copy ws1.[a1]
    .AutoFilter Field:=7, Criteria1:="Rack #2"
    .Copy ws2.[a1]
    .AutoFilter Field:=7, Criteria1:="Rack #3"
    .Copy ws3.[a1]
    End With
    ActiveSheet.AutoFilterMode = False
    Application.ScreenUpdating = True
    End Sub
    Last edited by kbmitch; 09-05-2013 at 02:57 PM.

+ 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. Replies: 3
    Last Post: 06-17-2013, 06:00 AM
  2. [SOLVED] Macro to copy 3 adjacent columns at a time to a separate worksheet & sort by Company name
    By anya1 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-20-2013, 06:50 AM
  3. Need help in writing a Macro to sort the columns in the worksheet
    By shanvin in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-27-2013, 01:04 AM
  4. [SOLVED] Code to copy, sort, paste data from one worksheet to another.
    By wheatgrass in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-03-2012, 11:08 AM
  5. Code to look up, copy, paste, sort data from one worksheet to another
    By wheatgrass in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 06-14-2012, 11:45 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