+ Reply to Thread
Results 1 to 4 of 4

Unwanted loop

  1. #1
    Registered User
    Join Date
    07-17-2013
    Location
    Slovakia
    MS-Off Ver
    Excel 2010
    Posts
    5

    Unwanted loop

    Hey!

    Let's say you have two workbooks opened and you want to run a macro everytime the "workbook 2" is deactivated. However, the macro should make some changes to this deactivated "workbook 2" and then deactivate it again. But this scenario obviously creates an infinite loop.

    My "workbook 2" code looks like this:

    Please Login or Register  to view this content.
    My Macro:

    Please Login or Register  to view this content.
    Is it possible to make it work without this unwanted loop?

    Thanks for any advice!

    Lukas

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Unwanted loop

    Hi,

    If you want to make changes to workbook 2 why are you first wanting to deactivate it only to reactivate it? Is there not some other event that you could use to make the change?

    But since you're not using Paste Special Values why not simply point AU29 to G29 with =G29, and similarly for AU30:AU120


    You may find the Application.EnableEvents = False instruction of some use in the appropriate place, followed later by an =True instruction.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    07-17-2013
    Location
    Slovakia
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Unwanted loop

    Thanks for the reply!

    To better understand what I'm trying to accomplish with this, please take a look at my older thread:
    http://www.excelforum.com/excel-gene...33#post3328333

    So, I have two workbooks opened. The first one is a database and the second one is a workbook, where I'm using some comboboxes to select the values from the database. However, everytime I sort some of the database columns, my comboboxes selections are messed up. Because of this, I would like to run this COPY/PASTE macro everytime I switch from the second workbook to this database workbook, so I have those comboboxes selections stored in other cells, in case I would like to sort anything in the database, and later I want to run another macro to paste them back after I sort something in the database workbook.

    Does it make sense?

    Thanks in advance!

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

    Re: Unwanted loop

    Not sure I follow why you are doing what you are doing, but you don't have to Activate a workbook to do something with it. Use a full range reference (Workbook.Sheet.Range) and it doesn't matter if the workbook is active or not.

    Maybe try something like this...

    Please Login or Register  to view this content.
    Don't use the .PasteSpecial method as that will reactivate the workbook and create an endless loop.
    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.

+ 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] Copy dynamically changing column and Paste using VBA Loop (Loop within Loop)
    By nixon72 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-12-2013, 12:46 PM
  2. Why did an inner loop variable start overwriting the outer loop range suddenly?
    By 111StepsAhead in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-16-2012, 03:24 PM
  3. Macro Loop Broken. Detects Max but doesn't continue loop
    By herchenbach in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-21-2011, 12:17 PM
  4. Macro to loop through all sheets and delete unwanted columns
    By LemonTwist in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-24-2009, 12:03 PM
  5. Loop a column on Sheet1 and loop a row on Sheet2 to find a match
    By johnnywinter in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-13-2009, 02:09 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