Have 2 sheets of data need to sort sheet 1 as sheet 2

Posted on 2007-08-08
Last Modified: 2010-03-05

I have Sheet 1 and sheet 2 in an excel.What i want is a macro which can ask me which sheets to be sorted as which.

Which colum does it need to take in sheet 1 or sheet2 to sort.

Question by:bsharath
    LVL 48

    Expert Comment

    You need to button that will prompt a inputbox that allow you to select the sheed that is goin to be sorted (in sheet1 ou sheet2) ?
    LVL 11

    Author Comment

    Yes ...

    Can i have a way to do this...
    LVL 13

    Accepted Solution

    'assume second sheet to be sorted as first sheet
    Sub sorttwosheets()
    ws1= InputBox("Enter the first sheet name") 'e.g Sheet1
    ws2= InputBox("Enter the second sheet name")'e.g Sheet2
    col1= InputBox("Enter the first sheet column name") 'e.g A
    col2 = InputBox("Enter the first sheet column name") 'e.g A
       For j=1 to Sheet1.UsedRange.Rows.Count
          For k=1 to Sheet2.UsedRange.Rows.Count
             if UCase(Sheet2.Cells(k,col2)) = UCase(Sheet1.Cells(j,col1)) then
                   Sheet2.Rows(s2row).Copy Destination:=Sheet2.Rows(60000)
                   Sheet1.Rows(j).Copy Destination:=Sheet2.Rows(s2row)
                   Sheet2.Rows(60000).Cut Destination:= Sheet2.Rows(k)
            End if

    End Sub

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Introduction This Article is a follow-up to my Mappit! Addin Article (, it was inspired by an email posting I made to EUSPRIG (, I will briefly cover: 1) An overvieā€¦
    This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
    This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
    This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now