Results 1 to 4 of 4

Find Max value in a changing (variable range)

Threaded View

  1. #1
    Registered User
    Join Date
    05-11-2009
    Location
    Dayton, OH
    MS-Off Ver
    Excel 2007
    Posts
    5

    Find Max value in a changing (variable range)

    I've been searching for a few days trying to figure this out however my feeble brain cannot solve this.

    Here's the deal..... I am trying to find the max value within a range (14 cells) contained in one column ("C" in this case). This range will change corresponding to the current cell. Ex. as the current cell moves down (or increases in number) the range of cells to find the Max in moves down (or increases in number) as well. The Max value will then be used as a variable in a equation but for now just getting it into a cell is fine. This seems like it would be easy but it is driving me absolutely batty!

    I currently have the non-working code located in a For loop that contains other calculations as well. I've taken those calculations out since they work fine but cloud the bad part.

    So far I have tried:

    For EMA_20 = 20 To 28
                  
             MaxVal =  Sheets(rv1).Range(Sheets(rv1).Cells(EMA_20 - 13, 3), Sheets(rv1).Cells(EMA_20, 3)).Max
            rv1.Cells(EMA_20, 7) = MaxVal        
            
        Next
    No dice... so I tried:

    For EMA_20 = 20 To 28
            
            MaxVal = Application.WorksheetFunction.Max(Range(rv1.Cells(EMA_20 - 13, 3), rv1.Cells(EMA_20, 3)))
            rv1.Cells(EMA_20, 7) = MaxVal
              
        Next
    Finally:

    For EMA_20 = 20 To 28
            
           Dim MyRange As Range
           Dim Startrng
           Dim Endrng
            
           Startrng = EMA_20 - 13
           Endrng = EMA_20
    
    Set MyRange = Range(Cells(Startrng, 3), Cells(Endrng, 3)) 
    
    MaxVal = MyRange.Find(What:=WorksheetFunction.Max(MyRange), LookIn:=xlValues)
    
    rv1.Cells(EMA_20, 7) = MaxVal
            
        Next
    Most of the time I get runtime error 9 Subscript out of range.

    The fix is probably very simple but like I said, I have a feeble mind. Thanks in advance for any help/hints!!

    Robert
    Last edited by Zambo; 05-13-2009 at 10:57 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1