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

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
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
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,917
Members
449,093
Latest member
dbomb1414

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
Back
Top