Solved

Help with excel 2010

Posted on 2011-09-05
3
272 Views
Last Modified: 2012-05-12
Hello

Can someone please assist me in writing a macro for the attached?

Basically all I need is for the macro to search column Q ‘client’ find all matching numbers eg ‘57337’ filter on that and then in column P ‘order’ it needs to find the lowest and highest number and copy both of those rows and past into a new sheet.

Can this be done?

Any assistance is appreciated!

test.xlsx
0
Comment
Question by:vegas86
  • 2
3 Comments
 
LVL 39

Accepted Solution

by:
nutsch earned 500 total points
ID: 36486487
This code should do it. Uncomment the two lines to get the title row copied too.

Thomas
Sub Macro2()
Dim cl As Range, lMax As Long, lMin As Long, lLoop As Long
Dim shtOrg As Worksheet, shtDest As Worksheet

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.DisplayAlerts = False

Set shtOrg = ActiveSheet

shtOrg.Cells(1, 1).AutoFilter
shtOrg.Cells(1, 1).CurrentRegion.AutoFilter Field:=17, Criteria1:="57337"

lMax = Application.WorksheetFunction.Subtotal(4, shtOrg.Columns(16))
lMin = Application.WorksheetFunction.Subtotal(5, shtOrg.Columns(16))

Set shtDest = Sheets.Add
lLoop = 1

'to get title row, uncomment lines below
'shtOrg.Rows(1).Copy shtDest.Rows(1)
'lLoop = 2

For Each cl In shtOrg.Cells(1, 1).CurrentRegion.Columns(16).SpecialCells(xlCellTypeVisible)
    If cl = lMax Or cl = lMin Then
        cl.EntireRow.Copy shtDest.Rows(lLoop)
        lLoop = lLoop + 1
    End If
Next

shtOrg.Cells(1, 1).AutoFilter

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.DisplayAlerts = True

End Sub

Open in new window

0
 

Author Closing Comment

by:vegas86
ID: 36486497
Works perfectly!!

Thank you!
0
 
LVL 39

Expert Comment

by:nutsch
ID: 36486521
Glad to help. Thanks for the grade.

Thomas
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

770 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