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:
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