View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Kevin Porter Kevin Porter is offline
external usenet poster
 
Posts: 38
Default Deleteing columns starting at a certain row.

I currently have a program that compares names in row 1 with another
spreadsheet and deletes the columns if the names aren't there. This was easy
as there was only 1 column under a name.

Now there is another column that I do not want at all. So I need it to
delete all the columns for names that are not there and the first two columns
for those that are.

Here is my current code:

With Sheets("Shreveport").Rows(2).Delete
Dim i As Long
Dim lastCol As Long
With Sheets("Shreveport")
lastCol = .Cells(1, "IV").End(xlToLeft).Column
For i = lastCol To 1 Step -1
If Len(Trim(.Cells(1, i))) < 0 Then
If Application.CountIf(Workbooks("Employee List for
Payroll1").Worksheets("List").Columns(2), .Cells(1, i)) = 0 Then
.Columns(i).Delete .Columns(i + 1).Delete
End If
End If
Next
End With

Any help would be appreciated.

Thanks.