+ Reply to Thread
Results 1 to 17 of 17

Display problems during and after complex macro

  1. #1
    Registered User
    Join Date
    11-25-2011
    Location
    Alaska
    MS-Off Ver
    Excel 2003
    Posts
    42

    Display problems during and after complex macro

    I've got a long complex macro. It cycles through 30+ sheets, moves a bunch of data around, activates and sets properties on 300+ charts so they don't move or size, and activates and updates data range for 300+ named chartobjects. It makes use of private subs and private functions. I shut off screen updates at the beginning, and turn it on at the end.

    2 Problems w/ questions:

    - After it's done, when I switch tabs (worksheets), the charts appear to be giant sized (some still activated) until I zoom out and click around in some open cells. How do I refresh, reset, deactivate, etc. or whatever I need to do so this doesn't happen?

    - While it's running, I still see scroll bars moving on right side, so something is happening despite having screen updates off. Why? How can I stop that from happen? Or should I not care?

    Thanks much,
    Frank

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Display problems during and after complex macro

    I suspect in your code you have several lines that either .Select or .Activate sheets, charts, ranges...etc. Those are often recorded in a macro, but usually can be eliminated e.g.; instead of something like...

    Please Login or Register  to view this content.
    You could use...
    Please Login or Register  to view this content.
    So go through your code and eliminate all .Select and .Activate commands.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    11-25-2011
    Location
    Alaska
    MS-Off Ver
    Excel 2003
    Posts
    42

    Re: Display problems during and after complex macro

    Quote Originally Posted by AlphaFrog View Post
    I suspect in your code you have several lines that either .Select or .Activate sheets, charts, ranges...etc. Those are often recorded in a macro, but usually can be eliminated e.g.; instead of something like...

    Please Login or Register  to view this content.
    You could use...
    Please Login or Register  to view this content.
    So go through your code and eliminate all .Select and .Activate commands.

    I've been able to do that with just about everything except chart objects. What I need to do is cycle through all 300 charts (they are named) and change the "Chart Data Range". The only way I've been able to get it to work is to use this code:

    Please Login or Register  to view this content.
    Tabname is the worksheet name (31 of them). ChartName is the name of the charts on each sheet - there's ten on each sheet. StartRow, StartCol, EndRow, EndCol are row and column numbers to define range where chart object looks for the data.

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Display problems during and after complex macro

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    11-25-2011
    Location
    Alaska
    MS-Off Ver
    Excel 2003
    Posts
    42

    Re: Display problems during and after complex macro

    Quote Originally Posted by AlphaFrog View Post
    Please Login or Register  to view this content.
    You ROCK! That worked perfectly and shaved 10 seconds off the execution. I don't use the "With" very much, and I'm unsure of syntax, so every example helps. I have one more subroutine. This one sets properties on each chart. I'd like to see if you wouldn't mind helping do this one with "With" as well.

    Please Login or Register  to view this content.

    Thanks, Frank

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Display problems during and after complex macro

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    11-25-2011
    Location
    Alaska
    MS-Off Ver
    Excel 2003
    Posts
    42

    Re: Display problems during and after complex macro

    Quote Originally Posted by AlphaFrog View Post
    Please Login or Register  to view this content.

    I get a runtime error 445
    Object doesn't support this action.

    Debugger hits on this line:
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    11-25-2011
    Location
    Alaska
    MS-Off Ver
    Excel 2003
    Posts
    42

    Re: Display problems during and after complex macro

    From what I've read, I have to refer to each chartobject individually. If I understand this right (correct me please), ChartObjects is a collection, and it doesn't support that property?

  9. #9
    Registered User
    Join Date
    11-25-2011
    Location
    Alaska
    MS-Off Ver
    Excel 2003
    Posts
    42

    Re: Display problems during and after complex macro

    One more thing. I have a shape on a sheet called "START" .... button to allow user to launch the VBA routine. Not sure if that affects anything, but thought I'd let you know to be sure.

  10. #10
    Registered User
    Join Date
    11-25-2011
    Location
    Alaska
    MS-Off Ver
    Excel 2003
    Posts
    42

    Re: Display problems during and after complex macro

    Ok... using your stuff as an example, I found some code that seems to work. At least it doesn't crash the compiler. Give this a look and let me know if there's a more elegant way to do it.

    Please Login or Register  to view this content.

  11. #11
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Display problems during and after complex macro

    It works on the ChartObjects collection. I just tested it, and your original code selected the entire collection and applied it to the selection.

    The Start button shouldn't be an issue.

    I'm not sure why it errors. What sheet does it error on? And what type of charts ore on that sheet?

    You could restore the On Error Resume Next statement, but that's just masking the issue if there is one.

  12. #12
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Display problems during and after complex macro

    Quote Originally Posted by franklin_m View Post
    Ok... using your stuff as an example, I found some code that seems to work. At least it doesn't crash the compiler. Give this a look and let me know if there's a more elegant way to do it.

    Please Login or Register  to view this content.
    Well done.

    The With statement is most useful if you need to reference the With-object (myChart) multiple times. In this case, you only reference myChart once. So the With statement is extraneous. You could replace the With code block with this one line.

    myChart.Placement = xlFreeFloating

  13. #13
    Registered User
    Join Date
    11-25-2011
    Location
    Alaska
    MS-Off Ver
    Excel 2003
    Posts
    42

    Re: Display problems during and after complex macro

    Quote Originally Posted by AlphaFrog View Post
    Well done.

    The With statement is most useful if you need to reference the With-object (myChart) multiple times. In this case, you only reference myChart once. So the With statement is extraneous. You could replace the With code block with this one line.

    myChart.Placement = xlFreeFloating

    Thank you for the help. I'm really inexperienced using that. Information on using "With" in code seems spotty on the web. Not finding many sites that explain the "why" the syntax is the way it is. Using the recorder, you get "With" then a few properties changed, then it ends, then followed by another.

    Is there a limit to the number of properties that can be changed inside a "With" statement or is the structure recorded just an artifact of that process?

  14. #14
    Registered User
    Join Date
    11-25-2011
    Location
    Alaska
    MS-Off Ver
    Excel 2003
    Posts
    42

    Re: Display problems during and after complex macro

    I hate to trouble you more, but would you mind taking a moment to teach me a little of the "Why" behind how your code works?

    In the code below...

    (1) What is the purpose of the "." in front of Cells inside the .Range? I mean the obvious answer is "so it works", but I guess I'm looking to understand when they're needed and when not?

    (2) Could any of the methods that are members of "Chart" be set the same way? Can more than one be set? If so, would the syntax be similar but just more lines after the With Sheets?

    Please Login or Register  to view this content.

  15. #15
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Display problems during and after complex macro

    Quote Originally Posted by franklin_m View Post
    Thank you for the help. I'm really inexperienced using that. Information on using "With" in code seems spotty on the web. Not finding many sites that explain the "why" the syntax is the way it is. Using the recorder, you get "With" then a few properties changed, then it ends, then followed by another.

    Is there a limit to the number of properties that can be changed inside a "With" statement or is the structure recorded just an artifact of that process?

    There is no limit to the number of properties as long as they are members of the With-object.

    You may be overthinking the With code block. I understand it's new to you, but it's fairly simple. Think of it as a temporary variable. Any property or member within the code block that starts with a period refers to the With-obejct. It's a shorthand way of not having to repeatedly type the object every time you want to reference it.

    So going back to the first code where I used it
    Please Login or Register  to view this content.
    That code is exactly the same as this...
    Please Login or Register  to view this content.
    The With code block is just a more concise way to write the code. That's it.

    It doesn't speed up the code. The speed improvement to your original code was eliminating the Select and Activate commands by fully qualifying each reference with a worksheet.

    I hope that helps.

  16. #16
    Registered User
    Join Date
    11-25-2011
    Location
    Alaska
    MS-Off Ver
    Excel 2003
    Posts
    42

    Re: Display problems during and after complex macro

    Quote Originally Posted by AlphaFrog View Post
    There is no limit to the number of properties as long as they are members of the With-object.

    You may be overthinking the With code block. I understand it's new to you, but it's fairly simple. Think of it as a temporary variable. Any property or member within the code block that starts with a period refers to the With-obejct. It's a shorthand way of not having to repeatedly type the object every time you want to reference it.

    So going back to the first code where I used it
    Please Login or Register  to view this content.
    That code is exactly the same as this...
    Please Login or Register  to view this content.
    The With code block is just a more concise way to write the code. That's it.

    It doesn't speed up the code. The speed improvement to your original code was eliminating the Select and Activate commands by fully qualifying each reference with a worksheet.

    I hope that helps.

    Yeah, I'm over thinking it. That helps. Thanks for taking the time to explain. Really appreciate the help with this.

  17. #17
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Display problems during and after complex macro

    You're welcome.

+ 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] Need to search for and display complex data in large spreadsheet.
    By mithandir1 in forum Excel General
    Replies: 5
    Last Post: 01-26-2014, 06:14 PM
  2. complex problems count based on many levels of criteria
    By joannelittell in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 10-28-2013, 04:42 PM
  3. Ideas for a transparent/better display of complex table
    By MoneyPenny in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 02-05-2013, 03:25 PM
  4. Excel Old Timer but VBA Newbie looking for help solving more complex problems
    By spulliam2000 in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 01-14-2013, 07:26 PM
  5. Replies: 8
    Last Post: 05-04-2012, 08:43 PM
  6. Replies: 1
    Last Post: 03-28-2012, 03:43 AM
  7. Replies: 6
    Last Post: 10-11-2011, 03:03 PM
  8. [SOLVED] How do I resolve complex iteration problems in Excel?
    By William Sporborg in forum Excel General
    Replies: 7
    Last Post: 09-21-2005, 11:05 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