FAO Weaver - deleting columns VBA

Status
Not open for further replies.

Farback

Board Regular
Joined
Mar 27, 2009
Messages
149
You very kindly gave me this code for deleting columns with certain stated values - "Value A", "Value B" etc - in row 3:

Sub deleteCols()
Dim delArray As Variant, delRange As Range, addr As String
Dim str As Variant, found As Range, delCols As Range
delArray = Array("Value A", "Value B")
Set delRange = Rows(3)
For Each str In delArray
Set found = delRange.Find(what:=str)
If Not found Is Nothing Then
addr = found.Address
Do
If delCols Is Nothing Then
Set delCols = found
Else
Set delCols = Union(delCols, found)
End If
Set found = delRange.FindNext(found)
Loop While addr <> found.Address
End If
Next str
If Not delCols Is Nothing Then delCols.EntireColumn.Delete
End Sub

Is there a way of amending this to delete all columns with entries in column 3 EXCEPT those with certain values - "Value A", "Value B" etc?
.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Please continue in your original thread: http://www.mrexcel.com/forum/showthread.php?t=581544

All clarifications, directly related follow-ups, and bumps should be posted back to the original thread. Per forum rules, posts of a duplicate nature will be locked or deleted (rule #9 here: http://www.mrexcel.com/forum/showthread.php?t=99490). Weaver will also be much more likely to see your question for him if you post it back to the thread he already replied to.

Only start a new thread with an entirely new question.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,224,521
Messages
6,179,277
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top