Excel/VBA: Skip error and continue w/ code execution

Seth123

New Member
Joined
Apr 28, 2017
Messages
6
First, thanks a million to all who are here to share their expertise and to spend their time to solve the coding related problems of others. You have no clue how much you've helped me so far w/ my job.
Problem: My macro doesn't do what I want. I have an excel file w/ multiple columns. What I want is the macro 1) to look for specific headers (if they exist in the file), then 2) selects the entire column and 3) 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 w/o 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 col size of “Problem Description” to 50 ) did change to 6.
Should I use a different method to write this macro and avoid using OnErrorResumeNext? Any help is greatly appreciated!





<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; white-space: inherit;">OnErrorResumeNext
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


OnErrorResumeNext
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


OnErrorResumeNext
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


OnErrorResumeNext
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</code>
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
What happens with...

Code:
    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 GoTo 0

    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 GoTo 0

    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 GoTo 0
 
Upvote 0
this is taken care of now. i've found the solution below. thank you for your interest.




On Error Resume Next


Cells.Find("data domain").EntireColumn.ColumnWidth = 8
Cells.Find("eDIM#").EntireColumn.ColumnWidth = 6
Cells.Find("Problem Description").EntireColumn.ColumnWidth = 50
Cells.Find("Corrective Action Required?").EntireColumn.ColumnWidth = 6

On Error Goto 0
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,312
Members
452,634
Latest member
cpostell

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