Private sub macro looping :(

cmefly

Well-known Member
Joined
May 13, 2003
Messages
683
Hi,

i have the following macro and i'm unsure how to make it work properly:

Private Sub Worksheet_Change(ByVal Target As Range)
Select Case Range("c35").Value
Case "X"
Range("C37").ClearContents
End Select

Select Case Range("c37").Value
Case "X"
Range("C35").ClearContents
Exit Sub
End Select

End Sub

c35 and c37 are drop-down menus that contain either "X" or Blank. So when selecting X in either one, the other should result to Blank - but then this activates the first one and so only the first part really works....

any suggestions??

thanks,

Marc
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,286
Office Version
  1. 365
Platform
  1. Windows
Marc

Why 2 select case statements?

I think you might want something like this.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Select Case Target.Address
        Case "$C$35"
            If Target.Value = "X" Then Target.Offset(2).ClearContents
        Case "$C$37"
            If Target.Value = "X" Then Target.Offset(-2).ClearContents
    End Select
End Sub
 

wigi

Well-known Member
Joined
Jul 10, 2006
Messages
7,958
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
A possibility could be:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    
    Const sCell1 As String = "$C$35"
    Const sCell2 As String = "$C$37"
    
    If Target.Address = sCell1 Then
        If Target.Value = "X" Then
            Range(sCell2).Value = ""
        End If
    ElseIf Target.Address = sCell2 Then
        If Target.Value = "X" Then
            Range(sCell1).Value = ""
        End If
    End If

End Sub

Can you please use
Code:
 tags around your VBA code here? Thanks.
 

Watch MrExcel Video

Forum statistics

Threads
1,130,309
Messages
5,641,447
Members
417,209
Latest member
Agbarker

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top