Consulting

Results 1 to 8 of 8

Thread: Group 2 cells like in a userform.

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

    Group 2 cells like in a userform.

    I have cells B3 & D3 . One being a "YES" the other a "NO".

    Is there a way I can have it say if B3 = "a" then D3 = "" & if "D3" = "a" then B3 = ""

    I have this code.

    [VBA]Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Intersect(Range("B3,B5,B7,B9,B11,D3,D5,D7,D9,D11"), Target) Is Nothing Then
    Exit Sub

    End If

    If Target.Value = "a" Then

    Target.Value = ""

    Else

    Target.Value = "a"

    End If

    Cancel = True

    End Sub[/VBA]

    I tried this

    [VBA]
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Range("B3") = "a" Then Range("D3") = ""
    If Range("D3") = "a" Then Range("B3") = ""
    End Sub
    [/VBA]

    But not working the way I want it to work when B3 = "a" and i double click D3 it stays the same.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim OtherCell As String

    With Target

    If .Address = "$B$3" Then

    OtherCell = "D3"
    ElseIf .Address = "$D$3" Then

    OtherCell = "B3"

    Else

    Exit Sub
    End If

    Application.EnableEvents = False

    If .Value = "a" Then

    Me.Range(OtherCell).Value = ""
    ElseIf .Value = "" Then

    Me.Range(OtherCell).Value = "a"
    End If
    End With

    Application.EnableEvents = 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
    Aug 2007
    Location
    Windermere, FL, a 'burb in the greater Orlando metro area.
    Posts
    567
    Location
    <deleted by author>
    Ron
    Windermere, FL

  4. #4
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location
    That's good but can I have it if I double click the one that equals "a" it goes "".

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Goes where? It goes by setting the other.
    ____________________________________________
    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

  6. #6
    VBAX Tutor
    Joined
    Jan 2008
    Posts
    266
    Location
    i think he means like this

    [VBA]


    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim OtherCell As String

    With Target

    If .Address = "$B$3" Then

    OtherCell = "D3"
    ElseIf .Address = "$D$3" Then

    OtherCell = "B3"

    Else

    Exit Sub
    End If

    Application.EnableEvents = False

    If .Value = "a" Then

    Me.Range(OtherCell).Value = "a"
    Me.Range(Target.Address).Value = ""
    ElseIf .Value = "" Then

    Me.Range(OtherCell).Value = ""
    Me.Range(Target.Address).Value = "a"
    End If
    End With

    Application.EnableEvents = True

    End Sub


    [/VBA]

  7. #7
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
        Dim shortTermMemory As Variant
        If Target.Address = "$B$3" Or Target.Address = "$D$3" Then
            If Target.Value = "a" Then
                Application.EnableEvents = False
                With Range(Target, Range("C3"))
                    shortTermMemory = .Value
                    Range("b3:d3").Value = vbNullString
                    .Value = shortTermMemory
                End With
                Application.EnableEvents = True
            End If
        End If
    End Sub

  8. #8
    VBAX Expert
    Joined
    Apr 2007
    Location
    Orlando, FL
    Posts
    751
    Location
    Perfect Mikerickson that's exactly what I wanted thanks.

Posting Permissions

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