ExcelMaker007
New Member
- Joined
- Jul 14, 2020
- Messages
- 31
How to Delete column which column header starts with a value
xlPart really should be xlWhole otherwise the code would change a heading like "Awaken" to "ATRUE", even though it would not delete the column.
Both codes would be more robust with something, say, On Error Resume Next in case there were no headers with "Wake*" (eg the code accidentally gets run a second time)
I was under the impression that using xlWhole would cause it to ignore anything that exceeded "Wake", but maybe not "Wake*". Haven't tried that yet, but will. tx Peter.xlPart really should be xlWhole otherwise the code would change a heading like "Awaken" to "ATRUE", even though it would not delete the column.
Also needs xlWhole specified in case another Find has previously been done with xlPart in which case a similar issue to the above would arise.
This code would of course also incorrectly delete any column that happened to be missing a heading in row 3.
Both codes would be more robust with something, say, On Error Resume Next in case there were no headers with "Wake*" (eg the code accidentally gets run a second time)
Exactly, that's why I mentioned itLookAt,, SearchOder and MatchCase ... MS recommentds specifying these parameters on each use to avoid inadvertant results.
I din't mention MatchCase since the OP hasn't specified whether the match has to be case-specific or not & I din't mention SearchOrder since that is irrelevant to this question.Also needs xlWhole specified in case another Find has previously been done with xlPart in which case a similar issue to the above would arise.
How to handle that issue... Can we have try catch to itxlPart really should be xlWhole otherwise the code would change a heading like "Awaken" to "ATRUE", even though it would not delete the column.
Also needs xlWhole specified in case another Find has previously been done with xlPart in which case a similar issue to the above would arise.
This code would of course also incorrectly delete any column that happened to be missing a heading in row 3.
Both codes would be more robust with something, say, On Error Resume Next in case there were no headers with "Wake*" (eg the code accidentally gets run a second time)
Which issue?How to handle that issue... Can we have try catch to it
Sub ExcelMaker()
With Range("3:3")
.Replace "Wake*", True, xlWhole, , False, , False, False
On Error Resume Next
.SpecialCells(xlConstants, xlLogical).EntireColumn.Delete
On Error GoTo 0
End With
End Sub