View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Michael Michael is offline
external usenet poster
 
Posts: 791
Default Change which columns are deleted.

Change .Columns(i).Delete .Columns(i + 1).Delete to:
..Columns(i).Delete .Columns(i + 3).Delete
--
If this posting was helpful, please click on the Yes button.
Regards,

Michael Arch.




"Kevin Porter" wrote:

The following code worked great to see if a name was in a list, if it did not
then it deleted the column and the one after it. However, the PTB's have
added 2 additional columns that now need to be deleted. Basically, if the
name is not in the list then delete that column and the next 3. what should
I change to this code to make it do that? It would be easier to change this
code as opposed to change the way my other modules deal with the page after
it is created.

Sub ShreveportNameDelete()
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

If Sheets("Shreveport").Cells(5, 1) = "Total" Then
Sheets("Shreveport").Delete
End If

End Sub