PC Review


Reply
Thread Tools Rate Thread

Code to get Max Value in a perticular cell in ALL Sheets

 
 
Corey
Guest
Posts: n/a
 
      21st Jan 2008
I add sheets to a workbook sometimes on a daily basis and therefore do not know the last sheet
number or name until it has been created.

I need to gain the MAX value in cell J59 in ALL sheets, without having to NAME or KNOW the LAST
sheet, so if this changes i still get the correct MAX value.

Is there a line of code i can use for this ?

Corey....


 
Reply With Quote
 
 
 
 
Corey
Guest
Posts: n/a
 
      21st Jan 2008
Think i have a code that will work with a SLIGHT modification:
See arrow below in code:

Sub Workbook_Info()
On Error Resume Next
With Sheets("1") <==== How can i change THIS to ALL SHEETS in workbook INSTEAD
..Select
ActiveSheet.Unprotect
Range("R59").Select
ActiveCell.FormulaR1C1 = "=MAX('Enter-Exit Page:" & Worksheets(Worksheets.Count).Name &
"'!R[0]C[-8])"
End With
ActiveSheet.protect DrawingObjects:=True, Contents:=True, Scenarios:=True,
AllowFormattingCells:=True
End Sub



Corey....


"Corey" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
I add sheets to a workbook sometimes on a daily basis and therefore do not know the last sheet
number or name until it has been created.

I need to gain the MAX value in cell J59 in ALL sheets, without having to NAME or KNOW the LAST
sheet, so if this changes i still get the correct MAX value.

Is there a line of code i can use for this ?

Corey....



 
Reply With Quote
 
Joe
Guest
Posts: n/a
 
      21st Jan 2008
On Jan 21, 8:40*am, "Corey" <M...@WorkAgain.com.au> wrote:
> I add sheets to a workbook sometimes on a daily basis and therefore do notknow the last sheet
> number or name until it has been created.
>
> I need to gain the MAX value in cell J59 in ALL sheets, without having to NAME or KNOW the LAST
> sheet, so if this changes i still get the correct MAX value.
>
> Is there a line of code i can use for this ?
>
> Corey....



Dim Max as variant
Dim n As Single
For n = 1 To Sheets.Count
If n=1 then
Max = Worksheets(n).Range("J59")
Elseif Max < Worksheets(n).Range("J59")
Max = Worksheets(n).Range("J59")
Endif
Next n


HTH
Joe
 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      21st Jan 2008
If you run this code, the variable MaxValue will contain the maximum value
from all the R59 cells across all the worksheets (as shown by the MsgBox
statement at the end of the code)...

Sub MaxAcrossSheets()
Dim X As Long
Dim MaxValue As Double
Dim SheetName As String
MaxValue = Worksheets(1).Range("R29").Value
SheetName = Worksheets(1).Name
For X = 2 To Worksheets.Count
If Worksheets(X).Range("R29").Value > MaxValue Then
MaxValue = Worksheets(X).Range("R29").Value
SheetName = Worksheets(X).Name
End If
Next
MsgBox "Maximum Value: " & MaxValue & vbNewLine & _
"Sheet Name: " & SheetName
End Sub

Rick


"Corey" <(E-Mail Removed)> wrote in message
news:uDXJGF%(E-Mail Removed)...
> Think i have a code that will work with a SLIGHT modification:
> See arrow below in code:
>
> Sub Workbook_Info()
> On Error Resume Next
> With Sheets("1") <==== How can i change THIS to ALL SHEETS in workbook
> INSTEAD
> .Select
> ActiveSheet.Unprotect
> Range("R59").Select
> ActiveCell.FormulaR1C1 = "=MAX('Enter-Exit Page:" &
> Worksheets(Worksheets.Count).Name &
> "'!R[0]C[-8])"
> End With
> ActiveSheet.protect DrawingObjects:=True, Contents:=True,
> Scenarios:=True,
> AllowFormattingCells:=True
> End Sub
>
>
>
> Corey....
>
>
> "Corey" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> I add sheets to a workbook sometimes on a daily basis and therefore do not
> know the last sheet
> number or name until it has been created.
>
> I need to gain the MAX value in cell J59 in ALL sheets, without having to
> NAME or KNOW the LAST
> sheet, so if this changes i still get the correct MAX value.
>
> Is there a line of code i can use for this ?
>
> Corey....
>
>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
any way to check if a cell with perticular text is in the same pla Narnimar Microsoft Excel Misc 1 25th Nov 2008 10:27 PM
how do you match data and paste result in a perticular cell? KTN Microsoft Excel Worksheet Functions 3 6th Nov 2008 07:33 PM
How do i set up blink a perticular cell? aziz Microsoft Excel Misc 1 16th Jun 2008 03:33 PM
jump to perticular line in VBA code billypit786@gmail.com Microsoft Access Forms 1 27th Feb 2008 08:13 PM
how to assign a perticular signature to a perticular contat =?Utf-8?B?VGhlIERldmls?= Microsoft Outlook Contacts 1 17th Nov 2005 12:57 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:03 PM.