Problem: My macro doesn't do what I want. I have an excel file with multiple columns. What I want is the macro
- to look for specific headers (if they exist in the file), then
- selects the entire column and
- resize it as specified in the script. If the specified header doesn't exist in the file, the code should move on the next one without giving any error.
The code below changes the "Problem Description" size from 50 to 6 although 6 is the size for "Corrective Action Required?" header (which is not applicable in this case as that header doesn’t exist and hence the resizing requirement of 6 s/b simply ignored).
But that didn’t happened. Instead, the size of previous condition (changing the column size of "Problem Description" to 50 ) did change to 6.
Should I use a different method to write this macro and avoid using OnErrorResumeNext?
Sub Resize_specific_columns_OnErrResNxt()
'
' finds specific columns based on changed header names and resize them
On Error Resume Next
Cells.Find(what:="data domain", After:=ActiveCell, LookIn:= _
xlValues, lookat:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext _
, MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.EntireColumn.Select
Selection.ColumnWidth = 8
On Error Resume Next
Cells.Find(what:="eDIM#", After:=ActiveCell, LookIn:= _
xlValues, lookat:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext _
, MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.EntireColumn.Select
Selection.ColumnWidth = 6
On Error Resume Next
Cells.Find(what:="Problem Description", After:=ActiveCell, LookIn:= _
xlValues, lookat:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext _
, MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.EntireColumn.Select
Selection.ColumnWidth = 50
On Error Resume Next
Cells.Find(what:="Corrective Action Required?", After:=ActiveCell, LookIn:= _
xlValues, lookat:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext _
, MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.EntireColumn.Select
Selection.ColumnWidth = 6