+ Reply to Thread
Results 1 to 6 of 6

How to set up a variable range of rows for calculations in VBscript

  1. #1
    Registered User
    Join Date
    06-29-2020
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    3

    How to set up a variable range of rows for calculations in VBscript

    Hi all. I'm a long time lurker but first time poster. Thanks for all the great content on this site!

    I generate a report multiple times a day with varying data which is always formatted the same with exception to the number of "Results". I've created a macro to automatically resize columns, add columns, format, etc...but I'm stumped at how to perform a simple calculation of "Average", "Median", "Max", and "Min" on a range of values due to the fact that sometimes the range is performed on 10 rows, sometimes 8, sometimes 20, etc. I have highlighted the cells in the attached workbook with these simple calculations. I just need help identifying the code that will be flexible to allow for a varying number of Results every time I bring a report into my workbook. Thank you!!!
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: How to set up a variable range of rows for calculations in VBscript

    Quote Originally Posted by Spennyd76 View Post
    I'm stumped at how to perform a simple calculation of "Average", "Median", "Max", and "Min" on a range of values
    Where/How do you want those results?

  3. #3
    Registered User
    Join Date
    06-29-2020
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    3

    Re: How to set up a variable range of rows for calculations in VBscript

    Shoot, my apologies. I attached my spreadsheet before saving it with some changes. I'm attaching here again. The cells highlighted in yellow contain the calculations.

    Thank you!
    Attached Files Attached Files

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: How to set up a variable range of rows for calculations in VBscript

    Is this what you wanted?
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    06-29-2020
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    3

    Re: How to set up a variable range of rows for calculations in VBscript

    Thank you! That worked perfectly!! I'm not sure what the syntax is doing, but it worked. Thanks!

    It also got me thinking that other parts of my macro are bulky and too time consuming. In the sample spreadsheet I attached, is there a quick way of inserting a column between columns G and H but only for the table at the top? In other words, in the Sample spreadsheet, I'd insert a new column H from rows 14 to 25. But sometimes it would be rows 14 to 20, and other times 14 to 30. Right now, the way I'm doing it, it is simply inserting a new row for the whole spreadsheet and the macro is taking a long time to run. I'm wondering if it's because it's applying it to all 1,048,576 rows. ???

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: How to set up a variable range of rows for calculations in VBscript

    No code attached to .xlsx.

    You can ask one question per thread.
    You can continue if the new one is related to your original question, otherwise, please open a new thread.

+ 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. VBScript to Extract the Recent and Older rows to new sheet.
    By jagadeeshpj in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-07-2017, 12:43 AM
  2. Check multiple calculations where one variable is between a range
    By crise in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-06-2016, 11:16 AM
  3. excel 2007 macro need to have variable range of rows rather than fixed range
    By JW1028 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-20-2013, 02:45 PM
  4. Multiple Variable Worksheets problem -vbscript
    By SeraphicSoul in forum Excel General
    Replies: 0
    Last Post: 06-18-2012, 01:55 AM
  5. Datatype of Range for VBScript
    By TheBrigg in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-26-2012, 12:54 PM
  6. [SOLVED] Call VBScript from VBA, pass variable, return result to macro?
    By Ed in forum Excel Programming / VBA / Macros
    Replies: 26
    Last Post: 07-11-2006, 02:15 PM
  7. using data from an excel field in a variable in a VBscript (WSH)?
    By JurgenG in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-29-2005, 03:53 PM

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