+ Reply to Thread
Results 1 to 3 of 3

Worksheet_Change function

  1. #1
    Registered User
    Join Date
    01-25-2004
    Posts
    30

    Worksheet_Change function

    Hello
    This is my problem:
    beeing in a sheet, user can choose in a cell between a list of value (I used the option "data validation") - What I'd like to do, is that based on the selection from the user, I can "clear" some sections of my sheet ..

    So, in the Private Sub Worksheet_Change(ByVal Target As Range)
    function of my sheet, I have the following instruction :

    thisSheet.Range(Cells(target.Row, 7), Cells(target.Row, 16)).ClearContents
    (that is : clear cell from column 7 to 16 for the row = target.Row)

    The problem is that I get a loop : since each time a cell is zeroed, the Worksheet_change function is invoked and it restart again ..

    Is anyway to avoid the loop?


    thanks
    *pimar

  2. #2
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628
    Try to use a switch.

    For instance:
    Private Sub Worksheet_Change(ByVal Target As Range)
    Static sw As Boolean
    If Not sw Then 'this is the start condition
    sw = True
    Range(Cells(Target.Row, 7), Cells(Target.Row, 16)).ClearContents
    sw = falsee
    End If
    End Sub

    Regards,
    Antonio

  3. #3
    Registered User
    Join Date
    01-25-2004
    Posts
    30
    Thanks for the suggestion ..
    originally my doubt was if I'm using correctly the function, but your suggestion works fine, so I'm ok with that :-)

    thanks
    *pimar

+ 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