+ Reply to Thread
Results 1 to 3 of 3

Macro to get target value, clear range and put back target value

  1. #1
    Registered User
    Join Date
    03-25-2004
    Posts
    54

    Macro to get target value, clear range and put back target value

    Hey, guys.

    I need to enter something in a cell within a range, but, after entering the data, I need Excel to clear all the other cells of the range, because there must be only one cell with data within that range.

    So far, I managed to get it working, but if I use the Application.ScreenUpdating option, it gets into an infinite looping and crashes.

    I've attached a sample so you can see what I really intend to do.

    If there's anything to be corrected or rewritten, please be my guest and do whatever it takes to get the code smoother and correct.

    Thank you guys very much for your attention.

    brunces
    Attached Files Attached Files

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,882

    Re: Macro to get target value, clear range and put back target value

    FYI - Since you are making change to worksheet in the code itself, it will trigger another Worksheet_Change Event and falls into infinite loop.

    You should, set Application.EnableEvents to false at start of your code and turn it back on before exiting the sub.
    While you have it in your code, it's position is after you make change to cell (i.e. .ClearContents)
    So... code should be...
    Please Login or Register  to view this content.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  3. #3
    Registered User
    Join Date
    03-25-2004
    Posts
    54

    Re: Macro to get target value, clear range and put back target value

    CK76, thank you very much for your help and specially for your explanation. I did not know about that. Now it makes perfect sense to me.

    Cheers.

+ 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. Self Ajusting cell , moving to provide target to meet end of year target
    By andycuk7 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 02-15-2016, 11:22 AM
  2. Replies: 5
    Last Post: 12-16-2014, 05:47 PM
  3. [SOLVED] Change(ByVal Target As Range) does not work when Target value changes
    By LeonvL in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 01-07-2013, 06:59 PM
  4. [SOLVED] Worksheet_Change(ByVal Target As Range) - set to only update when 3 target cells changed?
    By trillium in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-07-2012, 06:40 PM
  5. [SOLVED] Need alternate syntax 'Select Case' on Target.Column and Target.Row at the same time.
    By 111StepsAhead in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-18-2012, 11:19 AM
  6. Worksheet_CHange (ByVal Target as Range) when target is formula cell
    By coasterman in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-09-2012, 07:00 PM
  7. Ranges:Target in Worksheet_SelectionChange(ByVal Target As Range)
    By Kevin McCartney in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-15-2005, 09:06 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