Consulting

Results 1 to 12 of 12

Thread: elimanate zero while taking minimum value

  1. #1
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location

    elimanate zero while taking minimum value

    i have 4 columns ,format of cell is text
    (10,2, , ,)

    Dim dblMin As Double
    dblMin = Application.Min(CDbl(Cells(1, 1)), CDbl(Cells(1, 2)), CDbl(Cells(1, 3),CDbl(Cells(1, 4)))

    i want to take min of 4 columns , when i take min its shows zero to me i need to eliminate zero and consider 2 as mininum

    please guide me regarding this ..with vba code bit urgent

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Dim dblMin As Double
    dblMin = Activesheet.Evaluate("MIN(IF(A11<>0,A11))")
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location
    code works fine if cell format is numeric or general
    but when cell format is text value displayed is zero

    still i am facing problem

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Be smart, change them to General not text

    [vba]

    Dim dblMin As Double
    dblMin = ActiveSheet.Evaluate("MIN(IF(A11<>0,--(A11)))")
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location
    i cannt change cell value to numeric from text

    if i can find second minimum value then my problem will be solved
    but still stuck to find the minimum value

    .

  6. #6
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location
    thanks for solving my problem

  7. #7
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location
    Dim dblMin As Double
    dblMin = ActiveSheet.Evaluate("MIN(IF(cells(1,1):cells(1,4)<>0,--(cells(1,1):cells(1,4)
    )))")

    it shows type mismatch what i am doing wrong please guide me

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Look at what I gave you, compare against what you wrote, and it should be obvious.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  9. #9
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location
    dim min as double
    dblMin = Active Sheet.Evaluate("MIN(IF(A1:d1<>0,--(A1:d1)))")
    please guide me to increment to (A2:d2<>0,--(A2:d2) so on
    ie.i want to increment to next row

  10. #10
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Dim min As Double
    Dim rng As Range
    Set rng = Range("A11")
    dblMin = ActiveSheet.Evaluate("MIN(IF(" & rng.Address(False, False) & _
    "<>0,--(" & rng.Address(False, False) & ")))")
    Set rng = Range("A22")
    dblMin = ActiveSheet.Evaluate("MIN(IF(" & rng.Address(False, False) & _
    "<>0,--(" & rng.Address(False, False) & ")))")
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  11. #11
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location
    thanks u ..My problem is solved

  12. #12
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location
    Dim rng As Range
    ii as integer
    ii=1

    Set rng = Range(Cells(ii, 1), Cells(ii, 4))

    MinVal = ActiveSheet.Evaluate("MIN(IF(" & rng.Address(False, False) & _
    "<>0,--(" & rng.Address(False, False) & ")))")

    ii=ii+1

    here i am incrementing (ii) value to increment to neat row.. and this works ..

    ...THANKS

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •