Clear range if conditional cell is blank

JJM0512

New Member
Joined
Jun 1, 2020
Messages
6
Office Version
  1. 2016
Platform
  1. Windows
Hi

I am trying to find a way of automatically clearing the contents of columns C:AT in row x if the user manually clears the contents in column B in row x.

I have found a way of doing it for the first row in my sheet (row 3), however I would like to replicate this for the succeeding 100 rows. The following VBA code works for row 3...

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Intersect(Target, Range("B3")) Is Nothing Then
        Range("C3:AT3").ClearContents
    End If
End Sub

I must also point out that this code succeeds the follwing VBA code...

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim p As Range

    For Each p In Range("A1:At1").Cells
        If p.Value = "N" Then
            p.EntireColumn.Hidden = True
        ElseIf p.Value = "Y" Then
            p.EntireColumn.Hidden = False

        End If
    Next p
End Sub

So it would need to be compatible with this one too.

Hope someone can help!

Thanks
Joe
 
Glad we could help & thanks for the feedback.
 
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Your requirement is on column B. Try again but deleting data in column B, you can delete multiple cells at the same time.


Try this

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim rng As Range, rng2 As Range, c As Range, p as range
 
  Set rng = Intersect(Target, Range("B3:B" & Rows.Count))
  If Not rng Is Nothing Then
    For Each c In rng
      If c.Value = "" Then
        Application.EnableEvents = False
        Range("C" & c.Row & ":AT" & c.Row).ClearContents
        Application.EnableEvents = True
      End If
    Next
  End If
 
   For Each p In Range("A1:At1").Cells
        If p.Value = "N" Then
            p.EntireColumn.Hidden = True
        ElseIf p.Value = "Y" Then
            p.EntireColumn.Hidden = False
        End If
    Next p
End Sub
Hero #2
 
Upvote 0

Forum statistics

Threads
1,214,959
Messages
6,122,476
Members
449,087
Latest member
RExcelSearch

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