PDA

View Full Version : [SOLVED:] Help with code



blackie42
10-20-2016, 02:20 AM
Hi,

I need to blank some adjacent cells when selecting from a dropdown list.

Using the following but getting an error 'Run time error '91', Object variable or With block variable not set'


If Intersect(Target, Range("G:G")) = "Scrub" Then Target.Offset(, 3).Resize(, 1).ClearContents

So if I select Scrub in G2 then J2 contents are cleared but then it bugs out.

Any help appreciated

thanks
Jon

mana
10-20-2016, 03:49 AM
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Dim r As Range
Dim c As Range

On Error Resume Next
Set r = Intersect(Target, Columns("G"))
On Error GoTo 0
If r Is Nothing Then Exit Sub

Application.EnableEvents = False

For Each c In r
If c.Value = "Scrub" Then c.Offset(, 3).ClearContents
Next
Application.EnableEvents = True

End Sub

blackie42
10-20-2016, 04:48 AM
Thanks Mana,

This works fine

regards
Jon