Clear the contents of lines based on the partial content of the first column

banik2008

New Member
Joined
Oct 25, 2012
Messages
5
Hello all,

I have an Excel file which I use to manually enter information about a group of co-workers, which looks like this:

In the first column, from A12 to A26, I have a list of names. In the range E12 to Z26, I then manually enter the necessary information as needed.

What I would need is, when I click on a button at the end of the month, to run a macro clearing the content of a whole line in the range E12 to Z26, but only whenever a name in range A12 to A26 starts with "X-".

I don't know if I'm clear, so lets say in cell A20 I have the following name: "X- Fred", I would need the whole line from E20 to Z20 to be cleared (leaving A20 untouched).

Thanks in advance for any help.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Attach the following code to a button and run:
Code:
Sub ClearRow()

Dim rng as Range

Application.ScreenUpdating = False

For Each rng in Range("A12:A26")
  If lcase(Left(rng,2))= "x-" Then rng.offset(,4).Resize(,22).ClearContents
Next rng

Application.ScreenUpdating = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,411
Messages
6,124,759
Members
449,187
Latest member
hermansoa

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