Solved

Help with excel 2010

Posted on 2011-09-05
3
271 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
Comment Utility
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
Comment Utility
Works perfectly!!

Thank you!
0
 
LVL 39

Expert Comment

by:nutsch
Comment Utility
Glad to help. Thanks for the grade.

Thomas
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

771 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

11 Experts available now in Live!

Get 1:1 Help Now