+ Reply to Thread
Results 1 to 2 of 2

Need help creating VBA looping code in "Worksheet_Change(ByVal Target As Range)"

  1. #1
    Registered User
    Join Date
    10-10-2003
    Posts
    31

    Need help creating VBA looping code in "Worksheet_Change(ByVal Target As Range)"

    I have a spreadsheet with a single column range, "UserInput," in A1...A40. I have a second single column range of equal dimensions called "DefaultValue" in D1...D40.

    Whenever the value in a UserInput cell is blank, I want code created in the VBA "Worksheet_Change(ByVal Target As Range)" procedure to copy the associated DefaultValue into that cell. If the user deletes everything in A35 for example, the cell is given the value in D35.

    This setup provides the user with a default value in each UserInput cell and allows him to edit that value. If he makes a mess of it he can simply delete what he did and the VBA code will automatically reassert the associated DefaultValue so he can start again.

    I've been unable to create looping code that provides this service ('for each cell in ... do, or with each, etc.) I know how to code these loops generically, but I'm lost in a sea of parentheses and dots in VBA 2007. Help appreciated - just a sample code block would probably do it for me.

    Jim

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,108

    Re: Need help creating VBA looping code in "Worksheet_Change(ByVal Target As Range)"

    Hello Jim. Place the following code in the Worksheet code window.

    Please Login or Register  to view this content.
    Last edited by Mumps1; 12-11-2012 at 03:13 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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