Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Delete Column having specific word/value

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 120
Default Delete Column having specific word/value

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 120
Default Delete Column having specific word/value

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Delete Column having specific word/value


I think you will find this a lot quicker:


Code:
--------------------
Sub Delete_Columns()
Dim I As Long
With ActiveSheet
For I = .UsedRange.Columns.Count To 1 Step -1
If Application.WorksheetFunction.CountIf(.Columns(I), "Delete") Then
.Columns(I).Delete
End If
Next
End With
End Sub
--------------------


--
The Code Cage Team

Regards,
The Code Cage Team
'The Code Cage' (http://www.thecodecage.com)
------------------------------------------------------------------------
The Code Cage Team's Profile: http://www.thecodecage.com/forumz/member.php?userid=2
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=34868

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Delete Column having specific word/value

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
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
delete a cell if it contains specific word Tim Excel Discussion (Misc queries) 1 February 2nd 06 04:31 PM
delete cell that doesn't contain a specific word [email protected] Excel Discussion (Misc queries) 1 October 12th 05 05:54 AM
Find a specific word in a column cottage6 Excel Programming 3 September 19th 05 08:01 PM
Finding specific word in column Phil #3 Excel Worksheet Functions 3 March 28th 05 09:00 AM
delete row contains specific word in an macro Jean-Francois Excel Discussion (Misc queries) 4 January 11th 05 11:40 PM


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

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

About Us

"It's about Microsoft Excel"