+ Reply to Thread
Results 1 to 3 of 3

How can I build a Range, use it and remember it in a variable for later in a function?

  1. #1
    Registered User
    Join Date
    07-06-2012
    Location
    Cave Creek, Arizona
    MS-Off Ver
    Excel 2003
    Posts
    3

    How can I build a Range, use it and remember it in a variable for later in a function?

    Hi!

    Here is my dilemma: I have an old set of VBA functions which I wrote that process a vendor pricing sheet from their config tool. I'm tired of manually entering in AutoSUMs at the bottom of each category (usually 4 but sometimes only 2 or 3) and then manually linking them to a summary at the top. Each of the up to four categories can have a variable number of lines, so the locations of the desired SUM cells also varies.

    I've found the proper place in the VBA funtion to add the code, but I can't figure out how to set the Ranges. If I try to use a variable to grab the top range for the SUM function, then I get a 'range' of object'_global' error. If I try to calculate it based on a Count variable used for the line by line processing, then I get an 'Application-defined or object-defined' error.

    This is probably stupid simple, but I can't seem to view it properly...

    [Uh, obviously I'm new here - how do you get that inside window with the code in it? I'll just attach a text file sample (reduced significantly, removing most of the existing code that processes each product line)...]

    Thanks!
    Attached Files Attached Files
    Last edited by Geek4eye; 07-08-2012 at 01:26 PM.

  2. #2
    Registered User
    Join Date
    07-06-2012
    Location
    Cave Creek, Arizona
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: How can I build a Range, use it and remember it in a variable for later in a function?

    Thanks to:
    kvsrinivasamurthy
    who posted in another thread titled:
    Autosum with VBA

    With that example as a starting point, I was able to build a Function to do the job. It turned out to be easier to reprocess the sheet rather than do it in line with the previous Function. This method uses string manipulation to create the Range values.

    Here is the code, which should be easier to read than kvsrinivasamurthy's, and is more general purpose for my use.

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    07-06-2012
    Location
    Cave Creek, Arizona
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: How can I build a Range, use it and remember it in a variable for later in a function?

    Oops, I forgot to link the SUM cell back up to the top of the sheet. Given that, since each category subtotal goes to a different place up top, it makes better sense to abandon the big OR statement and break them out into separate sets of code. Here is the first one:

    Formula: copy to clipboard
    Please Login or Register  to view this content.

+ 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