Range Problem
Try something like:
Dim rng1 As Range
Dim hpc As Double
Dim hpcStr As String
Dim fndCell As Range
Set rng1 = _
Application.Union(Range("E" & sr & ":" & "E" & num) _
, Range("G" & sr & ":" & "G" & num))
rng1.FormulaR1C1 = "=(RC[-1]-RC[-3])*100/(RC[-3])"
rng1.NumberFormat = "#,##0.0000"
hpc = Application.WorksheetFunction.Max(rng1)
hpcStr = Format(hpc, "#,##0.0000")
With rng1
Set fndCell = .Find(What:=hpcStr, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, MatchCase:=False)
End With
Regards
Rowan
jesmin wrote:
Hi Rown: Thanks for reply. I modified as you said. Now its only the
cells.find() thats not working. I am using this code(cells.find())
directly not in a function.
I have to find min and max cell from col E,G. These 2 cols are filled
with data by formula as shown below. The data are huge big decimal
numbers.('num' is a variable to count last row of current region)
dim rng1 as range
dim hpc as double
Set rng1 = _
Application.Union(Range("E" & sr & ":" & "E" & num), Range("G" & sr &
":" & "G" & num)
rng1.FormulaR1C1 = "=(RC[-1]-RC[-3])*100/(RC[-3]))"
hpc = Application.WorksheetFunction.Max(rng1)
--upto this works fine. Following not working:
With rng1
Set fndcell = Cells.Find(What:=hpc, LookIn:=xlValues, LookAt:= xlPart,
SearchOrder:=xlByColumns, SearchDirection:=xlNext , MatchCase:=False)
end with
--error: min value hpc is a very big double number and find() is not
working for this big number. fndcell=empty
I tried many ways.
(a)Formatted data like:rng1.numberformat="#.####". here data are being
formatted but when trying to find, its not finding. In sheet, the data
are still original big decimal whereas formatted data are 4 decimals.
(b)Using FIXED:
rng1.FormulaR1C1="=FIXED((RC[-1]-RC[-3])*100/(RC[-3]))),4)"
In this case min() does not work even.
hpc = Application.WorksheetFunction.Max(rng1)
--hpc=0
--Please help. I spent almost whole day nothing happened.
|