Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 149
Default Deleting Columns with String

The sub below deletes columns containing certain words or strings. My only
problem is if I pass a "*". If I have a cell has a "*", the below code
deletes almost all columns.

Can someone help me modify it so it will only effect cells with an asterisk?


Sub DeleteColumnswString(ByVal sString As String)

Dim LastCol As Long
Dim r As Long
LastCol = Range("IV1").End(xlToLeft).Column
Application.ScreenUpdating = False
For r = LastCol To 1 Step -1
If Application.CountIf(Columns(r), "*" & sString & "*") < 0 _
Then Columns(r).Delete
Next r
Application.ScreenUpdating = True

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default Deleting Columns with String

Astrisk is a special character. To delete Astrisk rows you will need to pass
in a tilde character ahead of the astisk...

"~*" instead of just "*"

HTH

"scott" wrote:

The sub below deletes columns containing certain words or strings. My only
problem is if I pass a "*". If I have a cell has a "*", the below code
deletes almost all columns.

Can someone help me modify it so it will only effect cells with an asterisk?


Sub DeleteColumnswString(ByVal sString As String)

Dim LastCol As Long
Dim r As Long
LastCol = Range("IV1").End(xlToLeft).Column
Application.ScreenUpdating = False
For r = LastCol To 1 Step -1
If Application.CountIf(Columns(r), "*" & sString & "*") < 0 _
Then Columns(r).Delete
Next r
Application.ScreenUpdating = True

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Deleting Columns with String

Sub Main()
DeleteColumnswString "*"
End Sub


Sub DeleteColumnswString(ByVal sString As String)

Dim LastCol As Long
Dim r As Long
If sString = "*" Then _
sString = "~*"
LastCol = Range("IV1").End(xlToLeft).Column
Application.ScreenUpdating = False
For r = LastCol To 1 Step -1
If Application.CountIf(Columns(r), "*" & sString & "*") < 0 _
Then Columns(r).Delete
Next r
Application.ScreenUpdating = True

End Sub

--
Regards,
Tom Ogilvy


"scott" wrote in message
...
The sub below deletes columns containing certain words or strings. My only
problem is if I pass a "*". If I have a cell has a "*", the below code
deletes almost all columns.

Can someone help me modify it so it will only effect cells with an

asterisk?


Sub DeleteColumnswString(ByVal sString As String)

Dim LastCol As Long
Dim r As Long
LastCol = Range("IV1").End(xlToLeft).Column
Application.ScreenUpdating = False
For r = LastCol To 1 Step -1
If Application.CountIf(Columns(r), "*" & sString & "*") < 0 _
Then Columns(r).Delete
Next r
Application.ScreenUpdating = True

End Sub




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding Columns, Then deleting old columns May Excel Discussion (Misc queries) 4 October 30th 08 04:44 PM
Combining Text from 2 Columns into 1 then Deleting the 2 Columns sleepindogg Excel Worksheet Functions 5 September 19th 08 12:36 AM
Deleting numbers in a string Cheri Excel Discussion (Misc queries) 5 June 19th 07 10:12 PM
Deleting Columns Jim Berglund Excel Programming 2 July 20th 04 10:01 PM
deleting extra spaces in a string Eric[_16_] Excel Programming 6 December 3rd 03 10:50 PM


All times are GMT +1. The time now is 03:54 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"