+ Reply to Thread
Results 1 to 4 of 4

Max/Min Value VBA From Column Not Working

Hybrid View

  1. #1
    Registered User
    Join Date
    10-29-2012
    Location
    Leeds
    MS-Off Ver
    Excel 2010
    Posts
    49

    Max/Min Value VBA From Column Not Working

    Hi,

    I'm trying this bit of code to obtain the max and min values and print them into Range C2 and E2, however I get a debug error (Run time error 438, object doesn't support this property or method)

      Dim rng1, rng2 As Range
    
        Set rng1 = Sheets("Plan").Range("C3:C40")
        Set rng2 = Sheets("Plan").Range("E3:E40")
    
        Sheets("Plan").Range("C2").Value = Application.WorkheetFunction.Min(rng1)
        Sheets("Plan").Range("E2").Value = Application.WorkheetFunction.Max(rng2)
    There must be something wrong with my syntax but I can't figure out what it is! Can somebody help please?

  2. #2
    Forum Expert
    Join Date
    02-22-2013
    Location
    London, UK
    MS-Off Ver
    Office 365
    Posts
    1,218

    Re: Max/Min Value VBA From Column Not Working

    Try,

    Sub test()
        Dim rng1 As Range, rng2 As Range
        With ThisWorkbook.Sheets("Plan")    'or delete thisworkbook for the activeworkbook
            Set rng1 = .Range("C3:C40")
            Set rng2 = .Range("E3:E40")
            .Range("C2").Value = Application.Min(rng1)
            .Range("D2").Value = Application.Max(rng2)
        End With
    End Sub

    or without declaring rng1 and rng2,
    Sub test()
        With ThisWorkbook.Sheets("Plan")    'or delete thisworkbook for the activeworkbook
            .Range("C2").Value = Application.Min(.Range("C3:C40"))
            .Range("D2").Value = Application.Max(.Range("E3:E40"))
        End With
    End Sub

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Max/Min Value VBA From Column Not Working

    Hi,

    You've spelled worksheet incorrectly.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Max/Min Value VBA From Column Not Working

    Thanks for the rep.

    Don't despair! I've received numerous similar T-shirts over the years and am thinking of opening a stall on my local market.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Column Chart Not Working if First Column has Zero
    By ker9 in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 03-28-2014, 10:36 AM
  2. [SOLVED] Setting individual column width sizes for multi column listbox with VB2011 Mac not working
    By Nitefox in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 2
    Last Post: 01-26-2014, 06:19 PM
  3. Macro from moving from column 12 to the next row of column 5 not working
    By catchnanan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-05-2013, 05:58 PM
  4. [SOLVED] Wonder Why My Formula for "Index & Match" Not Working on 2nd Column but 1st Column
    By cychua in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 01-16-2013, 07:22 AM
  5. Need copy the column d instead of column b, macro working fine for column b
    By audax48 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-20-2012, 04:32 PM
  6. Sum a column drag 2 next not working
    By famreeks in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 11-06-2010, 11:01 PM
  7. Why H column not working???
    By drvortex in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-27-2007, 08:59 AM

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