+ Reply to Thread
Results 1 to 21 of 21

Code behaves differently between "step into" and running outright

  1. #1
    Registered User
    Join Date
    04-11-2012
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2010
    Posts
    76

    Code behaves differently between "step into" and running outright

    Currently going through a VBA tutorial. This lesson involved writing a macro which enters text, copies and pastes the text in more cells, and then empties the clipboard. When I go through the macro stepwise, everything happens correctly and the clipboard empties. When I run the whole thing (F5), everything happens but the emptying of the clipboard.

    I'm not so much worried about the code itself, I'm just wondering why a macro would behave differently between the two modes.

    Here is the code:


    Sub testLesson12c2()

    Range("A1").Select
    Range("A1").Value = "Test"
    Selection.Copy

    Range("A2").Select
    ActiveSheet.Paste

    Range("A3").Select
    ActiveSheet.Paste

    Range("A4").Select
    ActiveSheet.Paste

    Application.CutCopyMode = False

    Range("A1").Select

    End Sub

    Any help would be appreciated!

  2. #2
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: Code behaves differently between "step into" and running outright

    depending where you step into the code, you may be missing key points, for example where the value in A1 is selected/copied.
    If you liked my solution, please click on the Star -- to add to my reputation

    If your issue as been resolved, please clearly state so and mark the thread as [SOLVED] using the thread tools just above the first post.

  3. #3
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Code behaves differently between "step into" and running outright

    theletterh,

    Welcome to the Excel Forum.


    Your macro code, in this instance, will run a lot faster if you do not use Select, Copy, Paste.

    Please Login or Register  to view this content.
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  4. #4
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Code behaves differently between "step into" and running outright

    theletterh,

    Training / Books / Sites as of 04/05/2012

    MrExcel's Products: Books, CDs, Podcasts Discuss topics related to Holy Macro! Products: Learn Excel from MrExcel, VBA and Macros for Microsoft Excel,Holy Macro! It's 2500 VBA Examples CD, Guerilla Data Analysis Using Microsoft Excel and Excel Knowledge Base CD and the MrExcel Podcasts.
    http://www.mrexcel.com/forum/forumdisplay.php?f=19

    Getting Started with VBA.
    http://www.datapigtechnologies.com/ExcelMain.htm

    If you are serious about learning VBA try
    http://www.add-ins.com/vbhelp.htm

    Excel Tutorials and Tips - VBA - macros - training
    http://www.mrexcel.com/articles.shtml

    Here's a good primer on the scope of variables.
    Scope Of Variables And Procedures

    See David McRitchie's site if you just started with VBA
    http://www.mvps.org/dmcritchie/excel/getstarted.htm

    What is a Visual Basic Module?
    http://www.emagenit.com/VBA%20Folder...vba_module.htm

    Ron de Bruin's intro to macros:
    http://www.rondebruin.nl/code.htm

    Creating custom functions
    http://office.microsoft.com/en-us/ex...117011033.aspx

    Writing Your First VBA Function in Excel
    http://www.exceltip.com/st/Writing_Y...Excel/631.html

    VBA for Excel (Macros)
    http://www.excel-vba.com/excel-vba-contents.htm

    VBA Lesson 11: VBA Code General Tips and General Vocabulary
    http://www.excel-vba.com/vba-code-2-1-tips.htm

    Excel VBA -- Adding Code to a Workbook
    http://www.contextures.com/xlvba01.html

    Learn to debug:
    http://www.cpearson.com/excel/debug.htm

    How To: Assign a Macro to a Button or Shape
    http://peltiertech.com/WordPress/how...tton-or-shape/

    User Form Creation
    http://www.contextures.com/xlUserForm01.html

    Excel Tutorials / Video Tutorials - Functions
    http://www.contextures.com/xlFunctions02.html

    INDEX MATCH - Excel Index Function and Excel Match Function
    http://www.contextures.com/xlFunctions03.html

    Excel Data Validation
    http://www.contextures.com/xlDataVal08.html#Larger
    http://www.contextures.com/excel-dat...ation-add.html

    Your Quick Reference to Microsoft Excel Solutions
    http://www.xl-central.com/index.html

    New! Excel Recorded Webinars
    http://www.datapigtechnologies.com/ExcelMain.htm

    Programming The VBA Editor - Created by Chip Pearson at Pearson Software Consulting LLC
    This page describes how to write code that modifies or reads other VBA code.
    http://www.cpearson.com/Excel/vbe.aspx

    VBA and Macros for Microsoft Excel, by Bill Jelen "Mr.Excel" and Tracy Syrstad

    Excel Hacks 100 Industrial-Strength Tips & Tools, by David & Traina Hawley

    VBA and Macros for Microsoft Excel 2007, by Bill Jelen "Mr.Excel" and Tracy Syrstad

    Excel 2007 Book: you can try this...there is a try before you buy ebook available at this link…

    by Stephen/ Bovey, Rob/ Green, John Bullen (Paperback - Feb 11, 2005)
    Professional Excel Development

    by Rob Bovey, Stephen Bullen, John Green, and Robert Rosenberg (Paperback - Sep 26, 2001)
    Excel 2002 VBA: Programmers Reference

    DonkeyOte: My Recommended Reading, Volatility
    http://www.decisionmodels.com/calcsecretsi.htm

    Sumproduct
    http://www.xldynamic.com/source/xld.SUMPRODUCT.html

    Arrays
    http://www.xtremevbtalk.com/showthread.php?t=296012

    Pivot Intro
    http://peltiertech.com/Excel/Pivots/pivotstart.htm

    Email from XL - VBA
    http://www.rondebruin.nl/sendmail.htm

    Outlook VBA
    http://www.outlookcode.com/article.aspx?ID=40

    Function Dictionary
    http://www.xlfdic.com/

    Function Translations
    http://www.piuha.fi/excel-function-name-translation/

    Dynamic Named Ranges
    http://www.contextures.com/xlNames01.html

    How to create Excel Dashboards
    http://www.contextures.com/excel-dashboards.html
    http://chandoo.org/wp/excel-dashboards/
    http://chandoo.org/wp/management-dashboards-excel/
    http://www.exceldashboardwidgets.com/

    Excel Dashboard / Scorecard Ebook
    http://www.qimacros.com/excel-dashboard-scorecard.html

    Mike Alexander from Data Pig Technologies
    Excel 2007 Dashboards & Reports For Dummies

    Templates
    http://www.cpearson.com/Excel/Topic.aspx
    http://www.contextures.com/excel-tem...lf-scores.html

    Date & Time stamping:
    http://www.mcgimpsey.com/excel/timestamp.html

    Get Formula / Formats thru custom functions:
    http://dmcritchie.mvps.org/excel/formula.htm#GetFormat

    A nice informative MS article "Improving Performance in Excel 2007"
    http://msdn.microsoft.com/en-us/library/aa730921.aspx

    Progress Meters
    http://www.andypope.info/vba/pmeter.htm
    http://www.xcelfiles.com/ProgressBar.html

    And, as your skills increase, try answering posts on sites like:
    http://www.mrexcel.com
    http://www.excelforum.com
    http://www.ozgrid.com
    http://www.vbaexpress.com
    http://www.excelfox.com

  5. #5
    Registered User
    Join Date
    04-11-2012
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2010
    Posts
    76

    Re: Code behaves differently between "step into" and running outright

    Quote Originally Posted by DGagnon View Post
    depending where you step into the code, you may be missing key points, for example where the value in A1 is selected/copied.
    I've been stepping in at the beginning. It seems as though "Application.CutCopyMode = False" doesn't occur when I just hit F5.

  6. #6
    Registered User
    Join Date
    04-11-2012
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2010
    Posts
    76

    Re: Code behaves differently between "step into" and running outright

    Quote Originally Posted by stanleydgromjr View Post
    theletterh,

    Welcome to the Excel Forum.


    Your macro code, in this instance, will run a lot faster if you do not use Select, Copy, Paste.

    Please Login or Register  to view this content.
    Thank you, but my concern isn't with the code itself. Why would a macro behave differently between "step into" and "run"?

  7. #7
    Registered User
    Join Date
    04-11-2012
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2010
    Posts
    76

    Re: Code behaves differently between "step into" and running outright

    bump no response

  8. #8
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: Code behaves differently between "step into" and running outright

    it shoudl run exactly the same, what exactly are you doing to run in step into mode?

  9. #9
    Registered User
    Join Date
    04-11-2012
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2010
    Posts
    76

    Re: Code behaves differently between "step into" and running outright

    Quote Originally Posted by DGagnon View Post
    it shoudl run exactly the same, what exactly are you doing to run in step into mode?
    I'm in the code window in the visual basic editor, hitting F8 over and over.

  10. #10
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: Code behaves differently between "step into" and running outright

    as long as you run it right through to the end the result should be exactly the same.

  11. #11
    Registered User
    Join Date
    04-11-2012
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2010
    Posts
    76

    Re: Code behaves differently between "step into" and running outright

    Quote Originally Posted by DGagnon View Post
    as long as you run it right through to the end the result should be exactly the same.
    I agree wholeheartedly.

  12. #12
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: Code behaves differently between "step into" and running outright

    also worth noting when testing on my system both methods ran the same.

  13. #13
    Registered User
    Join Date
    04-11-2012
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2010
    Posts
    76

    Re: Code behaves differently between "step into" and running outright

    Could there be a setting that I need to change?

  14. #14
    Registered User
    Join Date
    04-11-2012
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2010
    Posts
    76

    Re: Code behaves differently between "step into" and running outright

    OK, here's something weird. I know that the macro has run successfully when the paste button becomes unclickable, an indication that the clipboard has been emptied. While in visual basic editor, but keeping the paste button visible, I tried hitting F5 repeatedly, running the macro over and over. On the 5th run, the paste button became unclickable. The 6th through like 17th it was clickable, and then the 18th run it was unclickable again. It seems to work infrequently and randomly. Does my description make sense? And could there be any explanation?

    Sub question, is this concern of mine becoming ridiculous?

  15. #15
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: Code behaves differently between "step into" and running outright

    if you do split screen view so you can see both your excel window and the VBE you should be able to see what it is doing. have a watch from there and see what is happening as you step through, you will not need to togle between windows.

    sub answer: that is up to you

  16. #16
    Registered User
    Join Date
    04-11-2012
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2010
    Posts
    76

    Re: Code behaves differently between "step into" and running outright

    I did that, and I watched the macro run perfectly as I stepped through. When using F5 while watching, the macro works about 5% of the time.

  17. #17
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Code behaves differently between "step into" and running outright

    Is it possible this is another Skype Click to Call problem? See several related posts in this forum.

  18. #18
    Registered User
    Join Date
    04-11-2012
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2010
    Posts
    76

    Re: Code behaves differently between "step into" and running outright

    Well done, Cutter! That was it exactly.

  19. #19
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Code behaves differently between "step into" and running outright

    Hi theletterh
    I did a forum search on Skype Click to Call and received 218 hits (including yours). So, which of those hits resolved your issue? Please share with us.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  20. #20
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Code behaves differently between "step into" and running outright

    And a site like this The Code Cage is another resource for asking and answering questions.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  21. #21
    Registered User
    Join Date
    04-11-2012
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2010
    Posts
    76

    Re: Code behaves differently between "step into" and running outright

    This was the thread. I also noticed The Code Cage, and I learned from there that there is a new version of Skype Click to Call which doesn't screw with your clipboard.

+ 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