Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Find Max One Column Multiple Row Ranges

Posted on 2008-10-05
6
Medium Priority
?
534 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 22646482
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
ID: 22646654
I'm getting a "data type mismatch" error
0
 
LVL 81

Expert Comment

by:zorvek (Kevin Jones)
ID: 22646899
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:donisanp
ID: 22646942
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 2000 total points
ID: 22646974
Works for me. I added a command button to make the test easier.

Kevin
Experts-MaxTest.xls
0
 

Author Closing Comment

by:donisanp
ID: 31503263
Brilliant!  Exactly what I needed, thank you very much!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

660 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