+ Reply to Thread
Results 1 to 16 of 16

Dynamic Range for VBA manipulations

  1. #1
    Registered User
    Join Date
    08-31-2011
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2003/Excel 2007
    Posts
    37

    Dynamic Range for VBA manipulations

    I am working on a large macro that is currently working fine with a few spots that have a 'hardwired' range (such as A1:C1000). I originally 'hard-wired' the ranges just to get the macro working for BETA use. I am going back and trying to remove the specific ranges so the macro can find the correct volume of data and the size won't matter. Some of the areas I have changed are working fine, but I am having trouble getting other changes to work.

    For example I have changed
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    , which works fine.

    My plot uses
    Please Login or Register  to view this content.
    which also works.
    Selecting my print area also works (I found that function on the forum)
    Please Login or Register  to view this content.
    also works.
    The part that doesn't work: Before the plot section, I have to sort some data. My sort works with the specific range, but I can't get a dynamic range to work. The sort I am trying to use the dynamic range in is:
    Please Login or Register  to view this content.
    I've tried different versions of the methods used in other sections fo the macro in this last section, but to no avail. The most recent attempt
    Please Login or Register  to view this content.
    (above) fails at
    Please Login or Register  to view this content.
    I've been working on this off and on for over two weeks and it is time to ask for help. Please help...

    The last time I tried to upload a file, I couldn't, FYI in case you were wondering.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,194

    Re: Dynamic Range for VBA manipulations

    I haven't had the time to look at the "more complex" problem, but you could shorten some of your other code and reduce the variables.

    For example:

    Please Login or Register  to view this content.

    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Dynamic Range for VBA manipulations

    Another example:
    Please Login or Register  to view this content.
    Last edited by nilem; 10-27-2011 at 01:45 PM.

  4. #4
    Registered User
    Join Date
    08-31-2011
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2003/Excel 2007
    Posts
    37

    Re: Dynamic Range for VBA manipulations

    @TM Shucks, thanks! That is shorter.

    @nilem, Thank you, that worked in the sopt I had posted. I almost forgot that there is a unique sort that also needs fixed, but I want to see if I can adjust what you've given me on my own (helps me understand better). Still working on it...

    Very awesome help!Ya'll rock!

  5. #5
    Registered User
    Join Date
    08-31-2011
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2003/Excel 2007
    Posts
    37

    Re: Dynamic Range for VBA manipulations

    And stuck again. The part that I forgot to include on the first post that needed changed was
    Please Login or Register  to view this content.
    My attempt that made it the farthest through the code was
    Please Login or Register  to view this content.
    It hangs up at
    Please Login or Register  to view this content.
    I was trying to modify the original three level filter to the unique filter. The original script was a recorded macro. When I tried that line with the original
    Please Login or Register  to view this content.
    It didn't work, hence my above attempt.

    I really wanted to figure it out, but I think I have tried everything my (very) limited knowledge can come up with.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,194

    Re: Dynamic Range for VBA manipulations

    It would probably make life a lot easier for everyone if you uploaded a sample workbook with some typical, if de-sensitized, data.

    I'm sure that someone can "fix" your code or provide an alternative approach.

    Regards

  7. #7
    Registered User
    Join Date
    08-31-2011
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2003/Excel 2007
    Posts
    37

    Re: Dynamic Range for VBA manipulations

    In the past I haven't been able to upload attachments other than pictures. (And I never got a response from IT help about it). I just tested it again and a small xcel file worked. So I will see if I can make an example and upload it.

  8. #8
    Registered User
    Join Date
    08-31-2011
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2003/Excel 2007
    Posts
    37

    Re: Dynamic Range for VBA manipulations

    Frack...I have a test file and now it won't let me upload a file again. FYI, the message I get is that a security token is missing.

    So, unfortunately, no sample file. I really wish I could...

    To sum up what is going on, there are three columns of data per row beginning on row 2. Column A is a system label, column B is a sub-category, and column C is a number formatted as text (so that a 4.10 doesn't get confused with a 4.1). Some rows are identical to other rows, and some are a unique set of data. I need to find the unique rows of data (with all three columns staying with that one 'entry' per row). When I find the unique rows, that is copied to another page and then I re-expand all the data. The next piece of code compares the unique data on the plot tab to the data on the sort tab so it can count how many of a unique set were in the original data. The net result of how many unique sets of each data set is what is plotted on a graph.

    Again, I wish I could give an actual test example.

  9. #9
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Dynamic Range for VBA manipulations

    In general:
    - avoid 'activate' & 'select' in VBA
    - make references to cells/ranges/sheets

    e.g.
    Please Login or Register  to view this content.
    Last edited by snb; 10-27-2011 at 06:06 PM.



  10. #10
    Registered User
    Join Date
    08-31-2011
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2003/Excel 2007
    Posts
    37

    Re: Dynamic Range for VBA manipulations

    So "missing a security token" actually means "file too large" in my case.

    I have attached an excerpt of the workbook that includes the data of concern. I have been able to follow the suggested code thus far. What I can't figure out is why the code is now failing on an Activate command. The main sheet (the real one) works up to the filtUNQCOPY routine. With the old code in filtUNQCOPY, the rest of the routine runs fine.
    Attached Files Attached Files

  11. #11
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Dynamic Range for VBA manipulations

    This suffices to copy unique item from sheet 'Sort data' to sheet 'Plot data'.
    Please Login or Register  to view this content.
    Last edited by snb; 11-16-2011 at 06:13 PM.

  12. #12
    Registered User
    Join Date
    08-31-2011
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2003/Excel 2007
    Posts
    37

    Re: Dynamic Range for VBA manipulations

    @snb, I was trying to take out the 'hardwired' range and select the data using a dynamic range. Also, I don't quite follow the previous post using the split....it looks like it is used for manipulating text strings, but I couldn't figure out the connection.

  13. #13
    Registered User
    Join Date
    08-31-2011
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2003/Excel 2007
    Posts
    37

    Re: Dynamic Range for VBA manipulations

    Bump, no response.

  14. #14
    Registered User
    Join Date
    08-31-2011
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2003/Excel 2007
    Posts
    37

    Re: Dynamic Range for VBA manipulations

    @snb, I think I might have figured out what the previous suggest was trying to do. Was your previous suggestion using the split to label the headers and get rid of the Activate that I was using the insert the headers?

    I ask because I agree with your signature, I never put code I don't understand onto my computer.

  15. #15
    Registered User
    Join Date
    08-31-2011
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2003/Excel 2007
    Posts
    37

    Re: Dynamic Range for VBA manipulations

    Any thoughts? I can't figure out why a dynamic range selection works for one method and not another. I tried both of the previous suggested methods (which work fine elsewhere in the macro) but could not make either work in this part. Still stumped.

  16. #16
    Registered User
    Join Date
    08-31-2011
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2003/Excel 2007
    Posts
    37

    Re: Dynamic Range for VBA manipulations

    Bump, no response.

+ 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