+ Reply to Thread
Results 1 to 13 of 13

VBA Moving Average Macro Problem

  1. #1
    Forum Contributor
    Join Date
    10-25-2012
    Location
    Honolulu, Hawaii
    MS-Off Ver
    Excel 2013
    Posts
    128

    VBA Moving Average Macro Problem

    Hello to all and thankyou for reading this.

    My macro keeps getting an error on line 8 " wk.select "

    Why is this ? Any help will be appreciated !!!

    Aloha to all.

    Please Login or Register  to view this content.

  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
    44,420

    Re: VBA Moving Average Macro Problem

    I suspect that you have a hidden worksheet or two
    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 Contributor
    Join Date
    10-25-2012
    Location
    Honolulu, Hawaii
    MS-Off Ver
    Excel 2013
    Posts
    128

    Re: VBA Moving Average Macro Problem

    Hello,

    Thankyou for your reply, I checked for hidden worksheets and there are none.

  4. #4
    Forum Contributor
    Join Date
    10-25-2012
    Location
    Honolulu, Hawaii
    MS-Off Ver
    Excel 2013
    Posts
    128

    Re: VBA Moving Average Macro Problem

    Hello,

    Thankyou for your reply, I checked for hidden worksheets and there are none.

  5. #5
    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
    44,420

    Re: VBA Moving Average Macro Problem

    Any charts, protected worksheets? Is the structure of the workbook protected?

    Barring defining the variable i, your code runs unchanged. I don't know if it does what it is intended to do, but it runs through three sheets. So I'd say the code is ok and it's something to do with the workbook.

    Try it in an empty workbook.

  6. #6
    Forum Contributor
    Join Date
    10-25-2012
    Location
    Honolulu, Hawaii
    MS-Off Ver
    Excel 2013
    Posts
    128

    Re: VBA Moving Average Macro Problem

    Hello,


    Thankyou very much for your reply, much appreciated.

    I do not have any charts or protected sheets. The empty workbook seemed like a good idea and I got excited for a second until I tried it.

    It still doesn't work.

    Hmmmm

  7. #7
    Forum Contributor
    Join Date
    10-25-2012
    Location
    Honolulu, Hawaii
    MS-Off Ver
    Excel 2013
    Posts
    128

    Re: VBA Moving Average Macro Problem

    I am getting run time error 1004

  8. #8
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: VBA Moving Average Macro Problem

    Is it possible to post example workbook so we can see what's your code supposed to do? There's too much Select, ActiveCell in your code because there's no need to select each sheet to perform those actions.
    It will also make your code run much smoother and faster.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  9. #9
    Forum Contributor
    Join Date
    10-25-2012
    Location
    Honolulu, Hawaii
    MS-Off Ver
    Excel 2013
    Posts
    128

    Re: VBA Moving Average Macro Problem

    Hello,

    I figured it out. I changed ThisWorkbook.Worksheets to ActiveWorkbook.Worksheets,

    Thankyou very much for your time. I try to avoid using select etc.. in the code but I do not know of another way. I truly wish I did.

  10. #10
    Forum Contributor
    Join Date
    10-25-2012
    Location
    Honolulu, Hawaii
    MS-Off Ver
    Excel 2013
    Posts
    128

    Re: VBA Moving Average Macro Problem

    Hello,

    I figured it out. I changed ThisWorkbook.Worksheets to ActiveWorkbook.Worksheets,

    Thankyou very much for your time. I try to avoid using select etc.. in the code but I do not know of another way. I truly wish I did.

  11. #11
    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
    44,420

    Re: VBA Moving Average Macro Problem

    You're welcome. Thanks for the rep.

    ThisWorkbook is the workbook with the code in it. The ActiveWorkbook is what it says on the tin. Clearly not the same in this instance.

  12. #12
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: VBA Moving Average Macro Problem

    You're welcome. Thanks for adding rep points.
    Will try later to adapt your code without Select, Activecell etc...

  13. #13
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: VBA Moving Average Macro Problem

    As promised. Try this out.

    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)

Similar Threads

  1. Calculating a Moving Average (Problem with blank cells)
    By JimmyOS in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 04-19-2016, 06:19 AM
  2. Moving average problem
    By missami21 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 03-09-2016, 09:24 AM
  3. [SOLVED] Moving Average Data Output Problem - Analysis Toolpak
    By zanshin777 in forum Excel General
    Replies: 1
    Last Post: 10-08-2015, 01:22 AM
  4. Macro for moving average and charting
    By sramalin in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-13-2011, 01:49 AM
  5. Exponential Moving Average Macro
    By erock24 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-25-2009, 11:27 PM
  6. [SOLVED] Moving Average Formula Problem
    By [email protected] in forum Excel General
    Replies: 3
    Last Post: 03-21-2006, 07:55 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