VBA to Delete Columns with text string & Wildcards

edokhotnik

Board Regular
Joined
Nov 10, 2010
Messages
104
Thank you in advance for your assistance. I am trying to delete entire columns in which the headers have a given text string - some attempting to use wildcards.
Excel Workbook
ABCDEFG
1JobNumberLocationIdContactVersion7Contact1Version13
21OHV-1234AbeAutocorrectJoshuaRemove constraints
32SDV-2345JohnBuild LaterAmyRemove requirements
43MNV-3456BillRefineJaneObtain permit
54MNV-3456TonyRemovalRitaBuild Foundation
Sheet1
Excel 2010
Excel Workbook
AB
1IdVersion13
2V-1234Remove constraints
3V-2345Remove requirements
4V-3456Obtain permit - Build Foundation
Sheet2
Excel 2010

I am using the following code to do this, but can't get the wild card to work. I want to deleted all columns except for Id and any Version1*.

Code:
 Sub DelColsWildCards()
LC = Cells(1, Columns.Count).End(xlToLeft).Column
    For i = LC To 1 Step -1
        If Cells(1, i)<> "Id" And Cells(1, i)<> "Version1" & "*" _
        Then Cells(1, i).EntireColumn.Delete shift:=xlToLeft
        End If
    Next i
End Sub

I am also attempting to concatenate the cells in the Version1* column if the corresponding Id is the same.

Thanks
 
Last edited:

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,224,598
Messages
6,179,822
Members
452,946
Latest member
JoseDavid

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