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

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
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,115
Messages
6,128,919
Members
449,478
Latest member
Davenil

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