Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8638485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:44:24+00:00 2026-06-12T10:44:24+00:00

I have a program which opens many Excel workbooks and merges data from all

  • 0

I have a program which opens many Excel workbooks and merges data from all of them into a target workbook. After merging, it does some transformation of the data (column to row tranpose using custom logic) and then it adds some more columns using lookup data.

I have the following code

Sub consolidateFiles()
    On Error GoTO ErrorHandler

    processFiles
    transform
    addLookupData

    Exit Sub
    ErrorHandler:
    Debug.Print Err.Number & " = " & Err.Description & ", Source = " & Err.Source 
End Sub

Sub processFiles()
 'Here I open all the files in the directory and copy and paste into the target workbook. 
 'If there is an error here, I would like to know the file that caused the error 
 'and I would like to proceed to the next file after logging the error
End Sub

Sub transform()
 'Here I transform some of the data from column to year.
End Sub

Sub addLookupData()
 'Here I add some new columns by looking up the data in another sheet in the target  workbook. Here the lookups can return error
End Sub

I wanted to know what are the good programming practices to add error handling to my code. Right now, I have one global error handler which logs the error and continues the program. Is it a good idea to add error handling to each of the 3 sub-procedures that I am calling from my main procedure?

I read about using the undocumented ERL to get the line of error. How do we add line numbers in the VBA editor?

This is my first program in VBA. I have done a lot of Java programming, but there the error handling paradigm is very different. Hence, I would like to learn from experienced VBA programmers what are the good practices that I can follow.

I have read this excellent article which was linked in one of the questions related to VBA error handling in SO:

http://www.cpearson.com/excel/errorhandling.htm

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T10:44:25+00:00Added an answer on June 12, 2026 at 10:44 am

    Since I did not get any answers, I have tried to research more. Here are some article that I have found useful:

    http://www.techrepublic.com/blog/five-apps/five-tips-for-handling-errors-in-vba/339

    http://www.jpsoftwaretech.com/vba-tips-tricks-and-best-practices-part-four/

    http://www.fmsinc.com/tpapers/vbacode/debug.asp#BasicErrorHandling

    Also, I have found following a SingleExitPoint in each procedure (either with error or without error) as a good practice.

    Many of the ideas are stated/hinted at in the link that Siddharth provided. But they were not very clear to me until I read these articles.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a c++ program which generates many data files each of them containing
I have a program which dynamically generates a GUI. I don't know how many
I have a program producing a lot of data, which it writes to a
Ok, so I have this program with many (~300) threads, each of which communicates
I have developed a program in PHP which opens IE on a button click.
I have a program which needs to hold approximately 3000 open file descriptors in
I have a program which creates JButtons which are then added to a JPanel
I have a program which outputs a pair of words surrounded by spaces on
I have a program which prints a multi-page document. The first page is pre-printed
I have a program which I would like to run every X min the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.