PC Review


Reply
Thread Tools Rate Thread

Delete Column having specific word/value

 
 
SANDIND
Guest
Posts: n/a
 
      28th Nov 2008
Hi All,

I wanna help writing a Macro that can delete the whole Column if that column
has anywhere any specific word/value for eg ."Delete".

I want to delete all such Columns in the sheet which contain anywhere
"delete".

Please help me on this . SS
 
Reply With Quote
 
 
 
 
PBezucha
Guest
Posts: n/a
 
      28th Nov 2008
One of many ways:

Option Explicit
Sub DeleteColumsWithKeyword()
' Deletes entire columns if they in the s e l e c t e d range contain
Keyword
Dim Keyword As String, DefaultKeyword As String
Dim S As Range, R As Range, I As Long, J As Long, N As Long
Const Title As String = "Deleting all columns with Keyword"
Set S = Selection
DefaultKeyword = "Delete"
Keyword = InputBox("Keyword", Title, DefaultKeyword)
If Keyword = "" Then Exit Sub
N = S.Columns.Count
For I = N To 1 Step -1
Set R = S.Columns(I)
J = 0
On Error Resume Next
J = WorksheetFunction.Match(Keyword, R, 0)
If J > 0 Then S.Columns(I).Delete
Next I
End Sub

Regards
--
Petr Bezucha


"SANDIND" wrote:

> Hi All,
>
> I wanna help writing a Macro that can delete the whole Column if that column
> has anywhere any specific word/value for eg ."Delete".
>
> I want to delete all such Columns in the sheet which contain anywhere
> "delete".
>
> Please help me on this . SS

 
Reply With Quote
 
PBezucha
Guest
Posts: n/a
 
      28th Nov 2008
Sorry for a mistake in the 3rd row from the end:

Option Explicit
Sub DeleteColumsWithKeyword()
' Deletes entire columns if they in the s e l e c t e d range contain
Keyword
Dim Keyword As String, DefaultKeyword As String
Dim S As Range, R As Range, I As Long, J As Long, N As Long
Const Title As String = "Deleting all columns with Keyword"
Set S = Selection
DefaultKeyword = "Delete"
Keyword = InputBox("Keyword", Title, DefaultKeyword)
If Keyword = "" Then Exit Sub
N = S.Columns.Count
For I = N To 1 Step -1
Set R = S.Columns(I)
J = 0
On Error Resume Next
J = WorksheetFunction.Match(Keyword, R, 0)
If J > 0 Then S.Columns(I).EntireColumn.Delete
Next I
End Sub
--
Petr Bezucha


"PBezucha" wrote:

> One of many ways:
>
> Option Explicit
> Sub DeleteColumsWithKeyword()
> ' Deletes entire columns if they in the s e l e c t e d range contain
> Keyword
> Dim Keyword As String, DefaultKeyword As String
> Dim S As Range, R As Range, I As Long, J As Long, N As Long
> Const Title As String = "Deleting all columns with Keyword"
> Set S = Selection
> DefaultKeyword = "Delete"
> Keyword = InputBox("Keyword", Title, DefaultKeyword)
> If Keyword = "" Then Exit Sub
> N = S.Columns.Count
> For I = N To 1 Step -1
> Set R = S.Columns(I)
> J = 0
> On Error Resume Next
> J = WorksheetFunction.Match(Keyword, R, 0)
> If J > 0 Then S.Columns(I).Delete
> Next I
> End Sub
>
> Regards
> --
> Petr Bezucha
>
>
> "SANDIND" wrote:
>
> > Hi All,
> >
> > I wanna help writing a Macro that can delete the whole Column if that column
> > has anywhere any specific word/value for eg ."Delete".
> >
> > I want to delete all such Columns in the sheet which contain anywhere
> > "delete".
> >
> > Please help me on this . SS

 
Reply With Quote
 
SANDIND
Guest
Posts: n/a
 
      28th Nov 2008
PBezucha, thanks for your help !!

SS

"PBezucha" wrote:

> Sorry for a mistake in the 3rd row from the end:
>
> Option Explicit
> Sub DeleteColumsWithKeyword()
> ' Deletes entire columns if they in the s e l e c t e d range contain
> Keyword
> Dim Keyword As String, DefaultKeyword As String
> Dim S As Range, R As Range, I As Long, J As Long, N As Long
> Const Title As String = "Deleting all columns with Keyword"
> Set S = Selection
> DefaultKeyword = "Delete"
> Keyword = InputBox("Keyword", Title, DefaultKeyword)
> If Keyword = "" Then Exit Sub
> N = S.Columns.Count
> For I = N To 1 Step -1
> Set R = S.Columns(I)
> J = 0
> On Error Resume Next
> J = WorksheetFunction.Match(Keyword, R, 0)
> If J > 0 Then S.Columns(I).EntireColumn.Delete
> Next I
> End Sub
> --
> Petr Bezucha
>
>
> "PBezucha" wrote:
>
> > One of many ways:
> >
> > Option Explicit
> > Sub DeleteColumsWithKeyword()
> > ' Deletes entire columns if they in the s e l e c t e d range contain
> > Keyword
> > Dim Keyword As String, DefaultKeyword As String
> > Dim S As Range, R As Range, I As Long, J As Long, N As Long
> > Const Title As String = "Deleting all columns with Keyword"
> > Set S = Selection
> > DefaultKeyword = "Delete"
> > Keyword = InputBox("Keyword", Title, DefaultKeyword)
> > If Keyword = "" Then Exit Sub
> > N = S.Columns.Count
> > For I = N To 1 Step -1
> > Set R = S.Columns(I)
> > J = 0
> > On Error Resume Next
> > J = WorksheetFunction.Match(Keyword, R, 0)
> > If J > 0 Then S.Columns(I).Delete
> > Next I
> > End Sub
> >
> > Regards
> > --
> > Petr Bezucha
> >
> >
> > "SANDIND" wrote:
> >
> > > Hi All,
> > >
> > > I wanna help writing a Macro that can delete the whole Column if that column
> > > has anywhere any specific word/value for eg ."Delete".
> > >
> > > I want to delete all such Columns in the sheet which contain anywhere
> > > "delete".
> > >
> > > Please help me on this . SS

 
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
How can I delete all colums to the right of a specific column? ManhattanRebel Microsoft Excel Misc 5 6th May 2008 05:48 PM
Sum of Column with next column containing specific word =?Utf-8?B?U2FyYWg=?= Microsoft Excel Worksheet Functions 2 7th Jun 2007 05:12 PM
delete rows where a cell is blank in specific column GottaRun Microsoft Excel Discussion 3 7th Mar 2006 05:29 AM
To Delete the specific rows when blank is found on column A =?Utf-8?B?ZGRpaWNj?= Microsoft Excel Programming 3 5th Aug 2005 05:32 AM
Delete Entire Row in Excel if specific column does not contain a 7-digit number Dimitris Microsoft Excel Programming 1 7th May 2004 09:53 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:02 PM.