Solved

Find Max One Column Multiple Row Ranges

Posted on 2008-10-05
6
525 Views
Last Modified: 2012-06-21
Hello Experts:

Looking for a VBA script that will find the maximum value for a range of values in one column and repeat this between breaks.  The breaks are not uniform meaning that there may be 2-3 empty rows before the next set is found.  There may be even just one value in that set.  I'd like to display the maximum value in column B in the cell adjacent to the max value in column A.

Col A     Col B (Max Values)

1
2
3
4
5
15         15
9
8
10

5
6
7
12
45        45
31
23
8
6


1
4         4
2

15      15
0
Comment
Question by:donisanp
  • 3
  • 3
6 Comments
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
Comment Utility
Use this macro with the sheet to be evaluated active:

Public Sub AddMaxValues()

   Dim Target As Range
   
   With ActiveSheet
      Set Target = .Range(.[A1], .[A1].End(xlDown))
      Do
         Target.Offset(Application.Match(Application.Max(Target), Target, 0) - 1, 1).Resize(1, 1) = Application.Max(Target)
         If Target.Row + Target.Rows.Count > .Rows.Count Then Exit Do
         Set Target = Target.Offset(Target.Rows.Count).Resize(1).End(xlDown)
         Set Target = .Range(Target, Target.End(xlDown))
      Loop
   End With

End Sub

Kevin
0
 

Author Comment

by:donisanp
Comment Utility
I'm getting a "data type mismatch" error
0
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
Comment Utility
Then there is a discrepancy between what you posted in your question and what you are actually working with. Please post your workbook.

Kevin
0
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.

 

Author Comment

by:donisanp
Comment Utility
I've attached the file.  So in column B I'd like the macro to output the max value for each run.
Experts-MaxTest.xls
0
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 500 total points
Comment Utility
Works for me. I added a command button to make the test easier.

Kevin
Experts-MaxTest.xls
0
 

Author Closing Comment

by:donisanp
Comment Utility
Brilliant!  Exactly what I needed, thank you very much!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

762 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