Deleting data in multiple columns based on set criteria

Hannaford123

New Member
Joined
Jun 27, 2012
Messages
1
Hi - I have a spreadsheet with multiple columns containing teaching staff (3 x initials), or non teaching staff (number 1). I want to delete all the number 1's and regroup each column so that there are no blanks. I can't do this by using a filter as it also works across the rows whereas I want the columns to remain independent of each other. Can I set this up on a macro so that all the cells containing the number 1 are deleted and the remaining cells in each column move up? I can do each column manually but with 50+ columns there must be an easier way!
Thanks
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Hi,
Welcome to Board!
Try this:
(ON A COPY PL!)

Code:
Sub DeleteNonTeachers()
lr = ActiveSheet.UsedRange.Rows.Count  'last row
lc = ActiveSheet.UsedRange.Columns.Count  'last column
For r = lr To 1 Step -1
    For c = lc To 1 Step -1
        If Cells(r, c).Value = 1 Then Cells(r, c).Delete xlShiftUp 'kill
    Next c
Next r
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,113
Messages
6,128,905
Members
449,477
Latest member
panjongshing

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