View Single Post
 
Old 09-11-2020, 04:33 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,994
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Greg's use of functions is part of an effort to create modular code which over the long term enables you to reuse old code and save a lot of time. Many different projects need to get data from Excel. Greg's function enables him to copy and paste that chunk of code into many different projects and saves him lots of rework.

Say you have a large block of code and have 5 instances where you need to go out to Excel to get some tabular data. All 5 instances are essentially the process but the details will vary (what workbook, what sheet, is there headings at the top). Instead of repeating all the necessary coding in 5 places (which then has to be amended in 5 places if there is a problem), a function enables you to write it once and pass in those different input variables to get different datasets from the same code.

Subs and functions are similar but functions have the ability to return a variable (in this case a variant array). A function (or a sub with inputs) can't be run directly - they need to be called by other subroutines or functions.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote