I'm very new to this, so bare with me. What I'm trying to do is create a function that will delete all but a few specific named columns. We're getting data from a lab with a ton of columns in every sheet that we don't need, and I want to be able to quickly delete the superfluous info. I tried to convert another function I found, but can't get it to do what I want. As you'll see below, it was meant to delete one column with a certain name from a worksheet, and I tried to modify it by simply changing the "=" to "<>" and putting an "Or" in to find all the names I want. That didn't work.
Any help would be appreciated:
Sub SrmWtrColumnCleanup()
'Find last column with data in Row 1
lastCol = Cells(1, Columns.Count).End(xlToLeft).Column
'Loop through columns, starting at the last one
For delCol = lastCol To 1 Step -1
'Delete columns with Name in Row 1
If Cells(1, delCol) <> "SAMPLENAME" Or "SAMPDATE" Or "METHODCODE" Or "ANALYTE" Or "Result" Or "DL" Or "UNITS" Then _
Cells(1, delCol).EntireColumn.Delete
Next
End Sub
Bookmarks