Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Max and Min Worksheet function not giving whole value 1

Status
Not open for further replies.

vba317

Programmer
Mar 5, 2009
708
US
Hello,
I am using a max and min worksheet function that is not giving me the whole value. I was hoping that there was an enhancement that I could do to the code that would give me the correct value. To be more specific when I calculate the max value from one of my spreadsheets I get 87 instead of 87.43. I have highlighted in red the code that is doing the calculation in question. Any help would be appreciated.

Here is the code:

Code:
Sub Aleg_Bleg()
'
' Aleg_Bleg Macro
' Macro recorded 5/5/2009
'


Dim LR As Long
Dim ws As Worksheet
Dim wbResults As Workbook
Dim wbCodeBook As Workbook
Dim lCount As Long
Dim CL1 As Long

Dim ALegLowL As Long
Dim BLegHighL As Long

Dim ALegLowV1 As Long
Dim ALegLowV2 As Long
Dim ALegLowV3 As Long

Dim BLegHighV1 As Long
Dim BLegHighV2 As Long
Dim BLegHighV3 As Long

Dim DiffL As Long
Dim DiffV As Long


        'Calculate Last Row
        LR = ActiveSheet.UsedRange.Rows.Count
        
        'Clear cells
        If LR > 29 Then CL1 = LR - 30
        
        
        'Clear cells
    
     If LR > 29 Then Range("H" & CL1, "H" & LR).Value = ""
     If LR > 29 Then Range("I" & CL1, "I" & LR).Value = ""
     If LR > 29 Then Range("K" & CL1, "K" & LR).Value = ""
     If LR > 29 Then Range("L" & CL1, "L" & LR).Value = ""
    
   
    'Leg calculations
    ' Min Value Calculation
    'A leg Low location
     ALegLowL = LR - 17
    'A leg low header
     Range("H" & ALegLowL).Value = "Low = A leg"
    'A leg Value
    'A leg Value Calculation
    ' ALegLowV
     
     ALegLowV1 = 2
     [Red] ALegLowV2 = WorksheetFunction.Min(Range(Cells(ALegLowV1, "D"), Cells(LR, "D")))
     Range("I" & ALegLowL).Value = ALegLowV2 [/Red]
    
    'B leg High location
     BLegHighL = LR - 16
    '
     
    'B leg High header
     Range("H" & BLegHighL).Value = "High = B leg"
     
     'B leg Value
     'B leg Value Calculation
     
     BLegHighV1 = 2
     [Red] BLegHighV2 = WorksheetFunction.Max(Range(Cells(BLegHighV1, "C"), Cells(LR, "C")))
     Range("I" & BLegHighL).Value = BLegHighV2 [/Red]
     
    'Difference
    'Difference location
     DiffL = LR - 15
    'Difference header
     Range("H" & DiffL).Value = "Difference"
    
    'Difference Value
     DiffV = ALegLowV2 - BLegHighV2
     Range("I" & DiffL).Value = DiffV
'
End Sub
 
Have a look at data type definitions - Long is a variant of integer and therefore won't store decimal values

Have a look at using Double or Decimal data types

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top