+ Reply to Thread
Results 1 to 5 of 5

Calculating Min using variable ranges in VBA

  1. #1
    Registered User
    Join Date
    09-27-2012
    Location
    Adelaide, South Australia
    MS-Off Ver
    Excel 2010
    Posts
    6

    Calculating Min using variable ranges in VBA

    Hi fellow VBAers,

    Basically, in Sheet "USB_WLs" I have 3 columns similar to below:
    A B C
    1 1 3
    1 2 5
    1 3 16
    1 4 1
    2 1 3
    2 2 8
    3 1 9
    . . .
    . . .

    I require the minima of column C within each class or group defined by equal values in column A - i.e., min(class1) = 1, min(class2) = 3.

    Previously, I have written a VBA which defines the range of A(1), A(2) etc., in order to create new charts pertaining to the times series of C(i) (hence, Col B is time). The code is given below. Note that this code is correct.

    Please Login or Register  to view this content.
    I thought that calculating Min/Max/Ave of each of these groups in A would involve a simple alteration (given arguably the most difficult part is done - i.e., defining the variable ranges). I was wrong. This is what I have so far. I'm getting the error 91: Object variable or With block variable not set.

    Please Login or Register  to view this content.
    From what I've seen on this forum, when you require the use of xlApps you need to specify objects etc (e.g., Dim xlApp As Object). I'm not sure if that is necessary, but I have done it for all variables.

    Any assistance here would be appreciated hugely!

    Cheers,
    Matt
    Last edited by M Knowling; 09-28-2012 at 03:03 AM.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Calculating Min using variable ranges in VBA

    do you want find minimum of each column ?
    If solved remember to mark Thread as solved

  3. #3
    Registered User
    Join Date
    09-27-2012
    Location
    Adelaide, South Australia
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Calculating Min using variable ranges in VBA

    Hi Patel45,

    No. I require the minimum in column C within each class or group defined by equal values in column A.
    In the example I gave above, we see three 'classes' in column A (i.e., 1, 2 and 3). I require the minimum value in column C for each class. For example, min of class 1 = 1 (i.e., column c, row 4), min of class 2 = 3 (i.e., column c, row 4) etc etc.

    Regards,
    Matt

  4. #4
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Calculating Min using variable ranges in VBA

    hi Matt, please check attachment, option to solve your issue not using Excel functions, press Run button
    Attached Files Attached Files
    Last edited by watersev; 09-28-2012 at 07:34 AM.

  5. #5
    Registered User
    Join Date
    09-27-2012
    Location
    Adelaide, South Australia
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Calculating Min using variable ranges in VBA

    Thank you watersev!

+ 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