+ Reply to Thread
Results 1 to 3 of 3

Max value in 1 column when all values format are text

  1. #1
    coco
    Guest

    Max value in 1 column when all values format are text

    I have an error when I run this function
    "Application.WorksheetFunction.Max(rng)"
    because the information in C:C is in TEXT format.

    I mean, For example:
    In this case "rng" has only integer-numbers in a text format.
    Dim rng As Range
    Dim MaxUnit2 As Integer
    Dim MinUnit2 As Integer

    Set rng = Worksheets("Sheet1").Range("C:C")
    MaxUnit2 = Application.WorksheetFunction.Max(rng)
    MinUnit2 = Application.WorksheetFunction.Min(rng)

    Can I use the same function : "Application.WorksheetFunction.Max(...)" TYPE
    for this particular case?

    Thanks

    Coco


  2. #2
    Gary's Student
    Guest

    RE: Max value in 1 column when all values format are text

    Does VBA have the equivalent of the MAXA worksheet function? MAXA does not
    get upset by mixing numbers with text.
    --
    Gary's Student


    "coco" wrote:

    > I have an error when I run this function
    > "Application.WorksheetFunction.Max(rng)"
    > because the information in C:C is in TEXT format.
    >
    > I mean, For example:
    > In this case "rng" has only integer-numbers in a text format.
    > Dim rng As Range
    > Dim MaxUnit2 As Integer
    > Dim MinUnit2 As Integer
    >
    > Set rng = Worksheets("Sheet1").Range("C:C")
    > MaxUnit2 = Application.WorksheetFunction.Max(rng)
    > MinUnit2 = Application.WorksheetFunction.Min(rng)
    >
    > Can I use the same function : "Application.WorksheetFunction.Max(...)" TYPE
    > for this particular case?
    >
    > Thanks
    >
    > Coco
    >


  3. #3
    Dave Peterson
    Guest

    Re: Max value in 1 column when all values format are text

    If I were doing it in a cell, I'd use this formula:

    =MAX(IF(ISNUMBER(-C1:C100),--C1:C100))
    This is an array formula. Hit ctrl-shift-enter instead of enter. If you do it
    correctly, excel will wrap curly brackets {} around your formula. (don't type
    them yourself.)

    (and you can't use the whole column.)

    In code, that same formula could be evaluated like:

    Option Explicit
    Sub testme()

    Dim myRng As Range

    With ActiveSheet
    Set myRng = .Range("c1", .Cells(.Rows.Count, "C").End(xlUp))

    MsgBox .Evaluate("=MAX(IF(ISNUMBER(-" & myRng.Address(external:=True) _
    & "),--" & myRng.Address(external:=True) & "))")

    End With

    End Sub


    coco wrote:
    >
    > I have an error when I run this function
    > "Application.WorksheetFunction.Max(rng)"
    > because the information in C:C is in TEXT format.
    >
    > I mean, For example:
    > In this case "rng" has only integer-numbers in a text format.
    > Dim rng As Range
    > Dim MaxUnit2 As Integer
    > Dim MinUnit2 As Integer
    >
    > Set rng = Worksheets("Sheet1").Range("C:C")
    > MaxUnit2 = Application.WorksheetFunction.Max(rng)
    > MinUnit2 = Application.WorksheetFunction.Min(rng)
    >
    > Can I use the same function : "Application.WorksheetFunction.Max(...)" TYPE
    > for this particular case?
    >
    > Thanks
    >
    > Coco


    --

    Dave Peterson

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1