+ Reply to Thread
Results 1 to 3 of 3

Code not working as planned

  1. #1
    Registered User
    Join Date
    04-13-2009
    Location
    Chicago, USA
    MS-Off Ver
    Excel 2007
    Posts
    34

    Code not working as planned

    this is my code:
    Private Sub Worksheet_Change(ByVal Target As Range)
    '
    ' What_If Macro
    'This Macros deletes one cell if another has a value in it

    'For Medium duty cell inputs
    Application.EnableEvents = False
    If IsNumeric(Target.Value) Then
    'Clear the Invalid entry
    Range("L4").ClearContents
    Range("L5").ClearContents

    If Target.Address = "$K$4" Then
    Range("K5").ClearContents
    ElseIf Target.Address = "$K$5" Then
    Range("K4").ClearContents
    End If
    Else
    Range(Target.Address).ClearContents
    Target.Next = "Invalid Input"

    End If


    'For Severe Service cell inputs

    If IsNumeric(Target.Value) Then
    'Clear the Invalid entry
    Range("L28").ClearContents
    Range("L29").ClearContents

    If Target.Address = "$K$28" Then
    Range("K29").ClearContents
    ElseIf Target.Address = "$K$29" Then
    Range("K28").ClearContents
    End If
    Else
    Range(Target.Address).ClearContents
    Target.Next = "Invalid Input"

    End If


    'For Heavy Duty cell inputs

    If IsNumeric(Target.Value) Then
    'Clear the Invalid entry
    Range("L48").ClearContents
    Range("L49").ClearContents

    If Target.Address = "$K$48" Then
    Range("K49").ClearContents
    ElseIf Target.Address = "$K$49" Then
    Range("K48").ClearContents
    End If
    Else
    Range(Target.Address).ClearContents
    Target.Next = "Invalid Input"

    End If
    Application.EnableEvents = True

    End Sub
    --------
    It works perfectly for K4 and K5;

    However for L28, L29, L48, and L49 the invalid input entry is not showing up properly. Please let me know what I am doing incorrectly
    Last edited by sulavsingh6; 04-14-2009 at 03:53 PM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Code not working as planned

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    04-13-2009
    Location
    Chicago, USA
    MS-Off Ver
    Excel 2007
    Posts
    34

    Re: Code not working as planned

    Private Sub Worksheet_Change(ByVal Target As Range)
    '
    ' What_If Macro
    'This Macros deletes one cell if another has a value in it

    'For Medium duty cell inputs
    Application.EnableEvents = False
    If IsNumeric(Target.Value) Then
    'Clear the Invalid entry
    Range("L4").ClearContents
    Range("L5").ClearContents
    Range("L28").ClearContents
    Range("L29").ClearContents
    Range("L48").ClearContents
    Range("L49").ClearContents
    If Target.Address = "$K$4" Then
    Range("K5").ClearContents
    ElseIf Target.Address = "$K$5" Then
    Range("K4").ClearContents
    ElseIf Target.Address = "$K$28" Then
    Range("K29").ClearContents
    ElseIf Target.Address = "$K$29" Then
    Range("K28").ClearContents
    ElseIf Target.Address = "$K$48" Then
    Range("K49").ClearContents
    ElseIf Target.Address = "$K$49" Then
    Range("K48").ClearContents
    End If

    Else
    Range(Target.Address).ClearContents
    Target.Next = "Invalid Input"

    End If


    Application.EnableEvents = True

    End Sub
    ---------
    This fixes the error

+ 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