• VBA Max of a column (2000)

    Author
    Topic
    #441348

    Why doesn’t
    iMax = Application.WorksheetFunction.Max(Column(1))
    work?
    Is there a one-liner that does work? (w/o resorting to Evaluate)
    TIA –Sam

    Viewing 2 reply threads
    Author
    Replies
    • #1059524

      Try this two liner
      Columns(1).Select
      imax = Worksheetfunction.Max(Selection)

      Tom Duthie

      • #1059526

        That does not work and it violates
        Sam’s Second rule of XL programming:
        2) NEVER use or change the selection

        whisper But thanks anyway!

    • #1059527

      (Edited by mbarron on 05-Apr-07 14:26. edit 2 – got rid of extra =)

      Try this one:

      iMax = Application.WorksheetFunction.Max(Range(“A:A”))

      or

      iMax = Application.WorksheetFunction.Max(Cells(1, 2).EntireColumn)

      • #1059528

        Bizzare! That works! Thanks! I’d like to see an expalnation of why.

        BTW, I resorted to some really weird code instead:
        iMax = [Max(Sheet1!C:C]

        I don’t do that very often because there is a lot of overhead; ie, don’t do it in a loop. But, for initializing your variables, it’s quick & dirty. Dirty, because if you move column C, your code no longer works.

        • #1059533

          You could also use named ranges if you are going to be moving columns.

          imax = Application.WorksheetFunction.Max(Range(“sam”))

    • #1059534

      It should be

      iMax = Application.WorksheetFunction.Max(Columns(1))

      i.e. Columns instead of Column.

      Columns is the collection of columns (in this case of the ActiveSheet since you haven’t specified what it belongs to).
      Column returns the column number of a range that contains only one column. Column(1) makes no sense.

    Viewing 2 reply threads
    Reply To: VBA Max of a column (2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: