Consulting

Results 1 to 6 of 6

Thread: vb script help

  1. #1
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location

    vb script help

    I have the following vb script that works great but would like to add something to it that needs to be placed within the With formula I believe.

    [VBA]Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Intersect(Range("B5,B7,B9,B11,B13,D5,D7,D9,D11,D13,F7"), Target) Is Nothing Then
    Exit Sub
    End If
    With Target
    If .Value = "X" Then
    .Value = ""
    Else
    .Value = "X"
    Select Case .Column
    Case 2
    .Offset(, 2).ClearContents
    .Offset(, 4).ClearContents
    Case 4
    .Offset(, 2).ClearContents
    .Offset(, -2).ClearContents
    Case 6
    .Offset(, -2).ClearContents
    .Offset(, -4).ClearContents
    End Select
    End If
    End With

    Cancel = True
    End Sub[/VBA]

    I want to add this
    [VBA] If Range("D11").Value = "X" Then Range("B20").Value = "N/A"
    If Range("D11").Value = "" Then Range("B20:H20").Cells.ClearContents[/VBA]

    This part I had after the End With but i was doing it everytime someone double clicked a Target cell. So if someone input data in the "B20" cell then went back to a target cell and double clicked it if "D11" = "" it clears that range. Is there a fix for that?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Is this what you need?

    [vba]

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Intersect(Range("B5,B7,B9,B11,B13,D5,D7,D9,D11,D13,F7"), Target) Is Nothing Then
    Exit Sub
    End If
    With Target
    If .Value = "X" Then
    .Value = ""
    Else
    .Value = "X"
    Select Case .Column
    Case 2
    .Offset(, 2).ClearContents
    .Offset(, 4).ClearContents
    Case 4
    .Offset(, 2).ClearContents
    .Offset(, -2).ClearContents
    Case 6
    .Offset(, -2).ClearContents
    .Offset(, -4).ClearContents
    End Select
    End If
    If Target.Address(False, False) = "D11" And .Value = "X" Then Me.Range("B20").Value = "N/A"
    If Target.Address(False, False) = "D11" And .Value = "" Then Me.Range("B20:H20").Cells.ClearContents
    End With

    Cancel = True
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location
    It's not clearing out the N/A once it's there.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    What N/A, where?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location
    If "D11" = "X" then "B20" = "N/A", But if they click "B11" then "D11" = "" but "B20" stays as "N/A".

  6. #6
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location
    BUMP!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •