PC Review


Reply
Thread Tools Rate Thread

Change which columns are deleted.

 
 
=?Utf-8?B?S2V2aW4gUG9ydGVy?=
Guest
Posts: n/a
 
      8th Oct 2007
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
 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWljaGFlbA==?=
Guest
Posts: n/a
 
      8th Oct 2007
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

 
Reply With Quote
 
=?Utf-8?B?S2V2aW4gUG9ydGVy?=
Guest
Posts: n/a
 
      8th Oct 2007
Thanks for the idea Michael. By using your code and stepping throught it, I
was better able to see what was happening. When I used your code it deleted
the 3rd column over as opposed to the next three. So I changed the code to

.Columns(i).Delete
.Columns(i + 1).Delete
.Columns(i + 1).Delete
.Columns(i).Delete

This deleted the column I was on, then the column next to it, next to it
then itself again. I probably could acheive the same thing by telling to
delete itself 4 times, but this worked. There is probably a prettier way to
do this, but this works.

Thanks again



"Michael" wrote:

> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple wrksheets same columns globally change order of columns? Change order of columns multiple wkshts Microsoft Excel Programming 1 11th Sep 2008 06:04 PM
change settings for manually deleted items to go to deleted folder =?Utf-8?B?U2VhbGVkIE9uZQ==?= Microsoft Outlook Discussion 2 1st Aug 2006 08:34 PM
Deleted Columns replaced with formatted columns DAMman21 Microsoft Excel Misc 0 30th May 2006 10:31 PM
How do I change numbered columns to alphabet columns? =?Utf-8?B?Y21icmV3ZXI1NQ==?= Microsoft Excel Misc 2 20th Jan 2006 06:00 PM
Change so deleted emails don't open in deleted folder. =?Utf-8?B?R2VvcmdlIFZvbGxyYXRo?= Microsoft Outlook Discussion 1 11th Nov 2005 09:35 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:32 AM.