Code needed for Max & Min Values

hsandeep

Well-known Member
Joined
Dec 6, 2008
Messages
1,226
Office Version
  1. 2010
Platform
  1. Windows
  2. Mobile
I have B2:B10 which are dynamic cells & keeps on UPDATING (based on time criteria)
Corresponding MAXIMUM & MINIMUM values required in E2:E10 & F2:F10
Code required to accomplish.
I am using Excel 2007.
Thanks in adv.
Sheet1

BCDEF
MAXIMUMMINIMUM

<colgroup><col style="FONT-WEIGHT: bold; WIDTH: 30px"><col style="WIDTH: 64px"><col style="WIDTH: 64px"><col style="WIDTH: 64px"><col style="WIDTH: 73px"><col style="WIDTH: 64px"></colgroup><tbody>
[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]1[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]2[/TD]
[TD="align: right"]458.45[/TD]

[TD="align: right"]458.45[/TD]
[TD="align: right"]451.23[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]3[/TD]
[TD="align: right"]470.26[/TD]

[TD="align: right"]470.38[/TD]
[TD="align: right"]459.22[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]4[/TD]
[TD="align: right"]280.01[/TD]

[TD="align: right"]285.98[/TD]
[TD="align: right"]260.01[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]5[/TD]
[TD="align: right"]500[/TD]

[TD="align: right"]510.05[/TD]
[TD="align: right"]492.06[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]6[/TD]
[TD="align: right"]9999[/TD]

[TD="align: right"]10000[/TD]
[TD="align: right"]9874.2[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]7[/TD]
[TD="align: right"]2222[/TD]

[TD="align: right"]2255[/TD]
[TD="align: right"]2220[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]8[/TD]
[TD="align: right"]1111[/TD]

[TD="align: right"]1181[/TD]
[TD="align: right"]1111[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]9[/TD]
[TD="align: right"]1090[/TD]

[TD="align: right"]1090[/TD]
[TD="align: right"]1090[/TD]

[TD="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=cacaca]#cacaca[/URL] , align: center"]10[/TD]
[TD="align: right"]7755.33[/TD]

[TD="align: right"]775.33[/TD]
[TD="align: right"]7755.3[/TD]

</tbody>
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
How are your values in column B updated?
Manually? By formula? By link? Copy & Paste?
How frequently are they being updated?
Are they all being updated at once, or individually?
 
Last edited:
Upvote 0
how are your values in column b updated? Real time data
manually? By formula? By link? Copy & paste? By link
how frequently are they being updated? Contionously as long as the workbook remains opened

are they all being updated at once, or individually?
all gets updated contionously as long as the workbook remains opened
 
Upvote 0
Right-click on the sheet tab name at the bottom of the screen, select "View Code", and paste this VBA code in the resulting VBA window and see if it does what you want:
Code:
Private Sub Worksheet_Calculate()

    Dim cell As Range
    
    Application.EnableEvents = False
    
'   Loop through range of values that is being updated
    For Each cell In Range("B2:B10")
'       Check/update Maximum
        If cell > cell.Offset(0, 3) Then cell.Offset(0, 3) = cell
'       Check/update Minimum
        If cell < cell.Offset(0, 4) Then cell.Offset(0, 4) = cell
    Next cell
    
    Application.EnableEvents = True

End Sub
 
Upvote 0
Right-click on the sheet tab name at the bottom of the screen, select "View Code", and paste this VBA code in the resulting VBA window and see if it does what you want:
I will give correct report by tomorrow Sir
 
Upvote 0
Joe4

Observations found:
1) Range B2:B10 throws MAXIMUM (HIGHEST) value in E2:E10….that’s fine
2) BUT it does not throws MINIMUM (LOWEST) value in F2:F10? F2:F10 is Null everytime.
3) E2:E10 retains values even after the Workbook is re-opened!!! Can E2:E10 (& similarly F2:F10) keep 0 instead (AFTER the workbook is re-opened)?
 
Upvote 0
2) BUT it does not throws MINIMUM (LOWEST) value in F2:F10? F2:F10 is Null everytime.
I tested it out, and it works for me. I wonder if there was a "hiccup" in one of your links, and the connection for some values failed at some point, returning a null, and then it got stuck on that null.
Does it actually return the word "Null", return a blank, or something else? If we know what it is that is being returned in some cases, we can test and account for it.

3) E2:E10 retains values even after the Workbook is re-opened!!! Can E2:E10 (& similarly F2:F10) keep 0 instead (AFTER the workbook is re-opened)?
There were no requirements in the original post on when to reset these values. If that is a requirement, you should add a Workbook_Open script to clear those values out to start (upon opening the file).
I would caution you not to set them to 0 to start, as that will probably be your MINIMUM value going forward then, unless you have negative values, or unless we update the script to make it not consider 0 to be a possible minimum value.
 
Upvote 0
I tested it out, and it works for me...I tested it today also only to find F2:F10 containing only blanks NOT LOWEST value?. I wonder if there was a "hiccup" in one of your links "one of your links".......B2:B10 is Last Traded Price of stocks & ALL B2:B10 gets figures from another worksheet from the SAME Workbook. No sooner than the stocks are traded & the stock prices changes, it makes corresponding B2:B10 change. B2:B10 gets updated as and when the stocks gets traded...so as per me there is NO ISUUES of "hiccup" anytime, and the connection for some values failed at some point, returning a null, and then it got stuck on that null.
Does it actually return the word "Null", return a blank Return a blank, or something else? If we know what it is that is being returned in some cases, we can test and account for it.
 
Upvote 0
You did not respond to the second issue, regarding resetting of the values when the workbook is re-opened.
I prefer to make ALL the changes to the code at once, and not piece-meal, so if you answer that question also, I will see if I can make the necessary adjustments for you all at once.
 
Upvote 0
Can I make it as A1=1 or 0

as long as A1=1, B2:B10 should keep on throwing Max and min in E and F as soon as A1=0 it should stop throwing any values in E and F
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,144
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top