Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 150
Default Retain rows with Max values - Delete other rows

Hi,

The following rows in a sheet contain region-wise sales of two
products:

Product Region Sales
Toyota North 50
Nissan South 42
Toyota South 30
Toyota West 60
Nissan North 32
Nissan East 35
Nissan West 25
Toyota East 37

I am looking for VBA code that will retain only the rows with the
maximum sales for a product and delete the other rows.

ie for the above input, the output should be:

Toyota West 60
Nissan South 42

Thanks in Advance for the help.
Raj
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Retain rows with Max values - Delete other rows

One way
Sub deletenonmaxrows()
Application.ScreenUpdating = False
mc = 1
For i = Cells(Rows.Count, mc).End(xlUp).Row To 2 Step -1
maxval = Evaluate("MAX(IF((A2:A9=""" & Cells(i, mc) & """),C2:C9))")
If Cells(i, mc + 2) < maxval Then Rows(i).Delete 'MsgBox i
Next i
Application.ScreenUpdating = True
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Raj" wrote in message
...
Hi,

The following rows in a sheet contain region-wise sales of two
products:

Product Region Sales
Toyota North 50
Nissan South 42
Toyota South 30
Toyota West 60
Nissan North 32
Nissan East 35
Nissan West 25
Toyota East 37

I am looking for VBA code that will retain only the rows with the
maximum sales for a product and delete the other rows.

ie for the above input, the output should be:

Toyota West 60
Nissan South 42

Thanks in Advance for the help.
Raj


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Delete empty rows in excel in b/w rows with values Dennis Excel Worksheet Functions 3 August 28th 07 04:15 PM
delete rows with 0 values andresg1975 Excel Programming 1 September 29th 06 03:49 PM
Delete Rows where there are #N/A Values FIRSTROUNDKO via OfficeKB.com Excel Worksheet Functions 3 August 3rd 06 04:03 PM
Delete rows with numeric values, leave rows with text GSpline Excel Programming 5 October 11th 05 12:44 AM
VBA - Delete Drop Down, Retain Values ajocius[_15_] Excel Programming 1 July 31st 05 09:52 AM


All times are GMT +1. The time now is 10:25 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"