0

I am very novice at this, I need to apply the below to rows with VBA, can anyone advise please.

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.Cells.Count > 1 Then Exit Sub

    If Not Intersect(Target, Range("A59")) Is Nothing Then
        Range("B59:E59").ClearContents

    End If

     If Target.Cells.Count > 1 Then Exit Sub

    If Not Intersect(Target, Range("B59")) Is Nothing Then
        Range("C59:E59").ClearContents

    End If

    If Target.Cells.Count > 1 Then Exit Sub

    If Not Intersect(Target, Range("C59")) Is Nothing Then
        Range("D59:E59").ClearContents

    End If

    If Target.Cells.Count > 1 Then Exit Sub

    If Not Intersect(Target, Range("D59")) Is Nothing Then
        Range("E59").ClearContents

    End If

End With

I have five dependent dropdown list columns each one is dependent of the previous. I am trying to reset the cells once the previous column selection is changed. The above works fine but I do not know how to apply it to all rows or up to 10000 rows for example.

I would very much appreciate the guidance on this

Many thanks G

2
  • Hm... use loop depending on your preferences. Commented Jan 23, 2014 at 12:56
  • Don't know how to add a loop. Commented Jan 23, 2014 at 13:49

2 Answers 2

1

If you don't want to use a loop, you can try something like this:

Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.Cells.Count > 1 Then Exit Sub

  If Target.Row = 59 then
    If not IsEmpty(Target) then
      Range(Cells(59,Target.Column +1),Cells(59,"E")).ClearContents
    End If  
  End If
End Sub
Sign up to request clarification or add additional context in comments.

2 Comments

Many thanks for this, but this still wont solve the rows and will also delete any text in after column E. A loop formula would be great. Many thanks G
I didn't understand your problem. Can you provide a data example that this algorithm don't fit.
0

Try this one:

Private Sub Worksheet_Change(ByVal Target As Range)
    With Target
        If .Cells.Count > 1 Then Exit Sub

        If .Row >= 59 And .Row <= 10000 _
            And .Column <= 4 Then
            Range(Cells(.Row, .Column + 1), Cells(.Row, 5)).ClearContents
        End If
    End With
End Sub

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.