SlideShare ist ein Scribd-Unternehmen logo
1 von 16
Creating a User‑Defined Function
in Excel using VBA
       Microsoft Office Training
            Excel Training



               www.bluepecan.co.uk
• Excel includes many different functions that
  help you complete calculations, but have you
  ever wished for a function that that doesn’t
  exist in Excel? If you have, this tutorial will
  explain how to create a function DIY style.




                    www.bluepecan.co.uk
• You create custom functions in the Visual
  Basic Editor (VBE) which you can get to by
  clicking Tools > Macro > Visual Basic Editor or
  by using the shortcut key ALT F11. If you are
  using Excel 2007 click on the Developer ribbon
  and then click on the Visual Basic button.
• Once in the VBE environment you will need to
  create a module to hold your function. Click
  Insert > Module

                    www.bluepecan.co.uk
• A function is defined with a name (for the
  function) and if necessary between 1 and 60
  arguments. For example the Excel worksheet
  function VLookup has 4 arguments.




                   www.bluepecan.co.uk
A func tio n with no arg ume nts

• Several VBA functions such as rand() have no
  arguments. In the same way you can create
  custom functions that have no arguments.
  The following function will display the path
  and filename of the active workbook.




                   www.bluepecan.co.uk
Function File()
  File = ActiveWorkbook.FullName
End Function

• Notice the function starts and ends with
  ‘Function’ rather than sub.



                   www.bluepecan.co.uk
• Enter =File() into a worksheet to see the
  result.
  or
• Click on fx (Insert Function) and open the User
  Defined category to see your function listed
  here



                    www.bluepecan.co.uk
• The next function displays the username (as
  set in Tools | Options | General)
  Function User()
     User = Application.username
  End Function




                    www.bluepecan.co.uk
A Cus to m Func tio ns with Arg ume nts

• The following function simply calculates a value plus
  VAT. In an empty worksheet create a column of
  prices.
• Then switch to the VBE environment and in a module
  create the following custom function. Notice that
  with this function you need to place arguments in
  the brackets after the function name.
• The sales argument will require you to select the cell
  containing the sales value for which you wish to add
  the VAT to.

                       www.bluepecan.co.uk
Function vat(sales)
      vat = sales * 1.15
   End Function
• Use the VAT function to calculate the VAT
  inclusive value in your list of prices




                   www.bluepecan.co.uk
• We could also add a markup value as part of
  our function by adding a second argument.




                   www.bluepecan.co.uk
Function retail(sales, markup)
  retail = sales * (markup + 1) * 1.15
End Function




                    www.bluepecan.co.uk
• Enter a markup percentage on your worksheet
  and refer to this value in the second argument
  of the function (separated from the first by a
  comma).
• You can always use the functions argument
  dialogue box to enter cell references or
  values.


                   www.bluepecan.co.uk
• The following function calculates the amount
  of time that has elapsed between a start time
  and the end time.
• The function also works for times over two
  separate days, in other words when the start
  time is greater than the end time.



                   www.bluepecan.co.uk
Function CalTime(StartTime, EndTime)
  If StartTime > EndTime Then
  CalTime = EndTime - StartTime + 1
  Else
  CalTime = EndTime - StartTime
  End If
End Function

                  www.bluepecan.co.uk
• See this Excel training tutorial on the Blue
  Pecan website




                     www.bluepecan.co.uk

Weitere ähnliche Inhalte

Was ist angesagt?

Odbc and data access objects
Odbc and data access objectsOdbc and data access objects
Odbc and data access objectsSangeetha Sg
 
Visual Basic Programming
Visual Basic ProgrammingVisual Basic Programming
Visual Basic ProgrammingOsama Yaseen
 
Introduction to visual basic programming
Introduction to visual basic programmingIntroduction to visual basic programming
Introduction to visual basic programmingRoger Argarin
 
Javascript conditional statements
Javascript conditional statementsJavascript conditional statements
Javascript conditional statementsnobel mujuji
 
Java introdução ao eclipse
Java   introdução ao eclipseJava   introdução ao eclipse
Java introdução ao eclipseArmando Daniel
 
Curso Java Básico Aula 01: Introdução e Dicas para quem está Começando
Curso Java Básico Aula 01: Introdução e Dicas para quem está ComeçandoCurso Java Básico Aula 01: Introdução e Dicas para quem está Começando
Curso Java Básico Aula 01: Introdução e Dicas para quem está ComeçandoLoiane Groner
 
Minicurso de JavaScript (Portuguese)
Minicurso de JavaScript (Portuguese)Minicurso de JavaScript (Portuguese)
Minicurso de JavaScript (Portuguese)Bruno Grange
 
Error handling and debugging in vb
Error handling and debugging in vbError handling and debugging in vb
Error handling and debugging in vbSalim M
 
JavaScript: Variables and Functions
JavaScript: Variables and FunctionsJavaScript: Variables and Functions
JavaScript: Variables and FunctionsJussi Pohjolainen
 
C# Tutorial
C# Tutorial C# Tutorial
C# Tutorial Jm Ramos
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascriptambuj pathak
 
Asp .net web form fundamentals
Asp .net web form fundamentalsAsp .net web form fundamentals
Asp .net web form fundamentalsGopal Ji Singh
 

Was ist angesagt? (20)

Odbc and data access objects
Odbc and data access objectsOdbc and data access objects
Odbc and data access objects
 
Visual Basic Programming
Visual Basic ProgrammingVisual Basic Programming
Visual Basic Programming
 
Introduction to visual basic programming
Introduction to visual basic programmingIntroduction to visual basic programming
Introduction to visual basic programming
 
Aula01-JavaScript
Aula01-JavaScriptAula01-JavaScript
Aula01-JavaScript
 
Visual Studio IDE
Visual Studio IDEVisual Studio IDE
Visual Studio IDE
 
Javascript conditional statements
Javascript conditional statementsJavascript conditional statements
Javascript conditional statements
 
Intro To Scratch
Intro To ScratchIntro To Scratch
Intro To Scratch
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Java introdução ao eclipse
Java   introdução ao eclipseJava   introdução ao eclipse
Java introdução ao eclipse
 
Curso Java Básico Aula 01: Introdução e Dicas para quem está Começando
Curso Java Básico Aula 01: Introdução e Dicas para quem está ComeçandoCurso Java Básico Aula 01: Introdução e Dicas para quem está Começando
Curso Java Básico Aula 01: Introdução e Dicas para quem está Começando
 
Minicurso de JavaScript (Portuguese)
Minicurso de JavaScript (Portuguese)Minicurso de JavaScript (Portuguese)
Minicurso de JavaScript (Portuguese)
 
Error handling and debugging in vb
Error handling and debugging in vbError handling and debugging in vb
Error handling and debugging in vb
 
Algorithms KS1 & KS2
Algorithms KS1 & KS2Algorithms KS1 & KS2
Algorithms KS1 & KS2
 
JavaScript: Variables and Functions
JavaScript: Variables and FunctionsJavaScript: Variables and Functions
JavaScript: Variables and Functions
 
Java codes
Java codesJava codes
Java codes
 
01-Lógica de Programação .pptx
01-Lógica de Programação .pptx01-Lógica de Programação .pptx
01-Lógica de Programação .pptx
 
Aula02 - JavaScript
Aula02 - JavaScriptAula02 - JavaScript
Aula02 - JavaScript
 
C# Tutorial
C# Tutorial C# Tutorial
C# Tutorial
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
Asp .net web form fundamentals
Asp .net web form fundamentalsAsp .net web form fundamentals
Asp .net web form fundamentals
 

Ähnlich wie Creating A User‑Defined Function In Excel Using Vba

Learn VBA Training & Advance Excel Courses in Delhi
Learn VBA Training & Advance Excel Courses in DelhiLearn VBA Training & Advance Excel Courses in Delhi
Learn VBA Training & Advance Excel Courses in Delhiibinstitute0
 
Online Advance Excel & VBA Training in India
 Online Advance Excel & VBA Training in India Online Advance Excel & VBA Training in India
Online Advance Excel & VBA Training in Indiaibinstitute0
 
200 Mega eBook Collection- http://bit.ly/3WEZuYJ
200 Mega eBook Collection- http://bit.ly/3WEZuYJ200 Mega eBook Collection- http://bit.ly/3WEZuYJ
200 Mega eBook Collection- http://bit.ly/3WEZuYJDannySingh23
 
Luke Cushanick Admin Tips and Tricks for Salesforce Trailblazer Community Chr...
Luke Cushanick Admin Tips and Tricks for Salesforce Trailblazer Community Chr...Luke Cushanick Admin Tips and Tricks for Salesforce Trailblazer Community Chr...
Luke Cushanick Admin Tips and Tricks for Salesforce Trailblazer Community Chr...Anna Loughnan Colquhoun
 
Excel 2007-functions-formulas
Excel 2007-functions-formulasExcel 2007-functions-formulas
Excel 2007-functions-formulasSankar Natarajan
 
Unit ii introduction to vba
Unit ii introduction to vbaUnit ii introduction to vba
Unit ii introduction to vbaDhana malar
 
Excel VBA.pptx
Excel VBA.pptxExcel VBA.pptx
Excel VBA.pptxGiyaShefin
 
10Excel.03 (1).ppt
10Excel.03 (1).ppt10Excel.03 (1).ppt
10Excel.03 (1).pptkokila60
 
10Excel.03.ppt
10Excel.03.ppt10Excel.03.ppt
10Excel.03.pptkokila60
 
Tutorial Excel: Working with Formulas and Functions
Tutorial Excel: Working with Formulas and FunctionsTutorial Excel: Working with Formulas and Functions
Tutorial Excel: Working with Formulas and FunctionsFaridah Mohamad
 

Ähnlich wie Creating A User‑Defined Function In Excel Using Vba (20)

Learn VBA Training & Advance Excel Courses in Delhi
Learn VBA Training & Advance Excel Courses in DelhiLearn VBA Training & Advance Excel Courses in Delhi
Learn VBA Training & Advance Excel Courses in Delhi
 
Online Advance Excel & VBA Training in India
 Online Advance Excel & VBA Training in India Online Advance Excel & VBA Training in India
Online Advance Excel & VBA Training in India
 
200 Mega eBook Collection- http://bit.ly/3WEZuYJ
200 Mega eBook Collection- http://bit.ly/3WEZuYJ200 Mega eBook Collection- http://bit.ly/3WEZuYJ
200 Mega eBook Collection- http://bit.ly/3WEZuYJ
 
Luke Cushanick Admin Tips and Tricks for Salesforce Trailblazer Community Chr...
Luke Cushanick Admin Tips and Tricks for Salesforce Trailblazer Community Chr...Luke Cushanick Admin Tips and Tricks for Salesforce Trailblazer Community Chr...
Luke Cushanick Admin Tips and Tricks for Salesforce Trailblazer Community Chr...
 
Excel 2007-functions-formulas
Excel 2007-functions-formulasExcel 2007-functions-formulas
Excel 2007-functions-formulas
 
Unit ii introduction to vba
Unit ii introduction to vbaUnit ii introduction to vba
Unit ii introduction to vba
 
Excel 2007 Unit P
Excel 2007 Unit PExcel 2007 Unit P
Excel 2007 Unit P
 
Excel VBA.pptx
Excel VBA.pptxExcel VBA.pptx
Excel VBA.pptx
 
Excel-VBA
Excel-VBAExcel-VBA
Excel-VBA
 
10Excel.03.ppt
10Excel.03.ppt10Excel.03.ppt
10Excel.03.ppt
 
Excel formulas
Excel formulasExcel formulas
Excel formulas
 
Valuable_Shortcut.ppt
Valuable_Shortcut.pptValuable_Shortcut.ppt
Valuable_Shortcut.ppt
 
10Excel.03.ppt
10Excel.03.ppt10Excel.03.ppt
10Excel.03.ppt
 
10Excel.03.ppt
10Excel.03.ppt10Excel.03.ppt
10Excel.03.ppt
 
10Excel.03 (1).ppt
10Excel.03 (1).ppt10Excel.03 (1).ppt
10Excel.03 (1).ppt
 
10Excel.03.ppt
10Excel.03.ppt10Excel.03.ppt
10Excel.03.ppt
 
Tutorial Excel: Working with Formulas and Functions
Tutorial Excel: Working with Formulas and FunctionsTutorial Excel: Working with Formulas and Functions
Tutorial Excel: Working with Formulas and Functions
 
10Excel.03.ppt
10Excel.03.ppt10Excel.03.ppt
10Excel.03.ppt
 
Vbabook ed2
Vbabook ed2Vbabook ed2
Vbabook ed2
 
Learn Excel Macro
Learn Excel Macro  Learn Excel Macro
Learn Excel Macro
 

Kürzlich hochgeladen

call girls in candolim beach 9870370636] NORTH GOA ..
call girls in candolim beach 9870370636] NORTH GOA ..call girls in candolim beach 9870370636] NORTH GOA ..
call girls in candolim beach 9870370636] NORTH GOA ..nishakur201
 
办理西悉尼大学毕业证成绩单、制作假文凭
办理西悉尼大学毕业证成绩单、制作假文凭办理西悉尼大学毕业证成绩单、制作假文凭
办理西悉尼大学毕业证成绩单、制作假文凭o8wvnojp
 
REFLECTIONS Newsletter Jan-Jul 2024.pdf.pdf
REFLECTIONS Newsletter Jan-Jul 2024.pdf.pdfREFLECTIONS Newsletter Jan-Jul 2024.pdf.pdf
REFLECTIONS Newsletter Jan-Jul 2024.pdf.pdfssusere8ea60
 
Cheap Rate ➥8448380779 ▻Call Girls In Mg Road Gurgaon
Cheap Rate ➥8448380779 ▻Call Girls In Mg Road GurgaonCheap Rate ➥8448380779 ▻Call Girls In Mg Road Gurgaon
Cheap Rate ➥8448380779 ▻Call Girls In Mg Road GurgaonDelhi Call girls
 
Breath, Brain & Beyond_A Holistic Approach to Peak Performance.pdf
Breath, Brain & Beyond_A Holistic Approach to Peak Performance.pdfBreath, Brain & Beyond_A Holistic Approach to Peak Performance.pdf
Breath, Brain & Beyond_A Holistic Approach to Peak Performance.pdfJess Walker
 
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改atducpo
 
Lilac Illustrated Social Psychology Presentation.pptx
Lilac Illustrated Social Psychology Presentation.pptxLilac Illustrated Social Psychology Presentation.pptx
Lilac Illustrated Social Psychology Presentation.pptxABMWeaklings
 
Top Rated Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
Call Girls In Andheri East Call US Pooja📞 9892124323 Book Hot And
Call Girls In Andheri East Call US Pooja📞 9892124323 Book Hot AndCall Girls In Andheri East Call US Pooja📞 9892124323 Book Hot And
Call Girls In Andheri East Call US Pooja📞 9892124323 Book Hot AndPooja Nehwal
 
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girlsPooja Nehwal
 
Reinventing Corporate Philanthropy_ Strategies for Meaningful Impact by Leko ...
Reinventing Corporate Philanthropy_ Strategies for Meaningful Impact by Leko ...Reinventing Corporate Philanthropy_ Strategies for Meaningful Impact by Leko ...
Reinventing Corporate Philanthropy_ Strategies for Meaningful Impact by Leko ...Leko Durda
 
CALL ON ➥8923113531 🔝Call Girls Aliganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Aliganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Aliganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Aliganj Lucknow best sexual serviceanilsa9823
 
CALL ON ➥8923113531 🔝Call Girls Rajajipuram Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Rajajipuram Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Rajajipuram Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Rajajipuram Lucknow best sexual serviceanilsa9823
 
CALL ON ➥8923113531 🔝Call Girls Mahanagar Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Mahanagar Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Mahanagar Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Mahanagar Lucknow best sexual serviceanilsa9823
 
《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...
《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...
《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...ur8mqw8e
 
CALL ON ➥8923113531 🔝Call Girls Adil Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Adil Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Adil Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Adil Nagar Lucknow best Female serviceanilsa9823
 
Understanding Relationship Anarchy: A Guide to Liberating Love | CIO Women Ma...
Understanding Relationship Anarchy: A Guide to Liberating Love | CIO Women Ma...Understanding Relationship Anarchy: A Guide to Liberating Love | CIO Women Ma...
Understanding Relationship Anarchy: A Guide to Liberating Love | CIO Women Ma...CIOWomenMagazine
 
文凭办理《原版美国USU学位证书》犹他州立大学毕业证制作成绩单修改
文凭办理《原版美国USU学位证书》犹他州立大学毕业证制作成绩单修改文凭办理《原版美国USU学位证书》犹他州立大学毕业证制作成绩单修改
文凭办理《原版美国USU学位证书》犹他州立大学毕业证制作成绩单修改atducpo
 

Kürzlich hochgeladen (20)

call girls in candolim beach 9870370636] NORTH GOA ..
call girls in candolim beach 9870370636] NORTH GOA ..call girls in candolim beach 9870370636] NORTH GOA ..
call girls in candolim beach 9870370636] NORTH GOA ..
 
办理西悉尼大学毕业证成绩单、制作假文凭
办理西悉尼大学毕业证成绩单、制作假文凭办理西悉尼大学毕业证成绩单、制作假文凭
办理西悉尼大学毕业证成绩单、制作假文凭
 
REFLECTIONS Newsletter Jan-Jul 2024.pdf.pdf
REFLECTIONS Newsletter Jan-Jul 2024.pdf.pdfREFLECTIONS Newsletter Jan-Jul 2024.pdf.pdf
REFLECTIONS Newsletter Jan-Jul 2024.pdf.pdf
 
Cheap Rate ➥8448380779 ▻Call Girls In Mg Road Gurgaon
Cheap Rate ➥8448380779 ▻Call Girls In Mg Road GurgaonCheap Rate ➥8448380779 ▻Call Girls In Mg Road Gurgaon
Cheap Rate ➥8448380779 ▻Call Girls In Mg Road Gurgaon
 
Breath, Brain & Beyond_A Holistic Approach to Peak Performance.pdf
Breath, Brain & Beyond_A Holistic Approach to Peak Performance.pdfBreath, Brain & Beyond_A Holistic Approach to Peak Performance.pdf
Breath, Brain & Beyond_A Holistic Approach to Peak Performance.pdf
 
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改
办理国外毕业证学位证《原版美国montana文凭》蒙大拿州立大学毕业证制作成绩单修改
 
Lilac Illustrated Social Psychology Presentation.pptx
Lilac Illustrated Social Psychology Presentation.pptxLilac Illustrated Social Psychology Presentation.pptx
Lilac Illustrated Social Psychology Presentation.pptx
 
Top Rated Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Tingre Nagar ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Call Girls In Andheri East Call US Pooja📞 9892124323 Book Hot And
Call Girls In Andheri East Call US Pooja📞 9892124323 Book Hot AndCall Girls In Andheri East Call US Pooja📞 9892124323 Book Hot And
Call Girls In Andheri East Call US Pooja📞 9892124323 Book Hot And
 
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
9892124323, Call Girls in mumbai, Vashi Call Girls , Kurla Call girls
 
Reinventing Corporate Philanthropy_ Strategies for Meaningful Impact by Leko ...
Reinventing Corporate Philanthropy_ Strategies for Meaningful Impact by Leko ...Reinventing Corporate Philanthropy_ Strategies for Meaningful Impact by Leko ...
Reinventing Corporate Philanthropy_ Strategies for Meaningful Impact by Leko ...
 
CALL ON ➥8923113531 🔝Call Girls Aliganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Aliganj Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Aliganj Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Aliganj Lucknow best sexual service
 
CALL ON ➥8923113531 🔝Call Girls Rajajipuram Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Rajajipuram Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Rajajipuram Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Rajajipuram Lucknow best sexual service
 
CALL ON ➥8923113531 🔝Call Girls Mahanagar Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Mahanagar Lucknow best sexual serviceCALL ON ➥8923113531 🔝Call Girls Mahanagar Lucknow best sexual service
CALL ON ➥8923113531 🔝Call Girls Mahanagar Lucknow best sexual service
 
《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...
《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...
《塔夫斯大学毕业证成绩单购买》做Tufts文凭毕业证成绩单/伪造美国假文凭假毕业证书图片Q微信741003700《塔夫斯大学毕业证购买》《Tufts毕业文...
 
Model Call Girl in Lado Sarai Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Lado Sarai Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Lado Sarai Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Lado Sarai Delhi reach out to us at 🔝9953056974🔝
 
CALL ON ➥8923113531 🔝Call Girls Adil Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Adil Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Adil Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Adil Nagar Lucknow best Female service
 
escort service sasti (*~Call Girls in Paschim Vihar Metro❤️9953056974
escort service  sasti (*~Call Girls in Paschim Vihar Metro❤️9953056974escort service  sasti (*~Call Girls in Paschim Vihar Metro❤️9953056974
escort service sasti (*~Call Girls in Paschim Vihar Metro❤️9953056974
 
Understanding Relationship Anarchy: A Guide to Liberating Love | CIO Women Ma...
Understanding Relationship Anarchy: A Guide to Liberating Love | CIO Women Ma...Understanding Relationship Anarchy: A Guide to Liberating Love | CIO Women Ma...
Understanding Relationship Anarchy: A Guide to Liberating Love | CIO Women Ma...
 
文凭办理《原版美国USU学位证书》犹他州立大学毕业证制作成绩单修改
文凭办理《原版美国USU学位证书》犹他州立大学毕业证制作成绩单修改文凭办理《原版美国USU学位证书》犹他州立大学毕业证制作成绩单修改
文凭办理《原版美国USU学位证书》犹他州立大学毕业证制作成绩单修改
 

Creating A User‑Defined Function In Excel Using Vba

  • 1. Creating a User‑Defined Function in Excel using VBA Microsoft Office Training Excel Training www.bluepecan.co.uk
  • 2. • Excel includes many different functions that help you complete calculations, but have you ever wished for a function that that doesn’t exist in Excel? If you have, this tutorial will explain how to create a function DIY style. www.bluepecan.co.uk
  • 3. • You create custom functions in the Visual Basic Editor (VBE) which you can get to by clicking Tools > Macro > Visual Basic Editor or by using the shortcut key ALT F11. If you are using Excel 2007 click on the Developer ribbon and then click on the Visual Basic button. • Once in the VBE environment you will need to create a module to hold your function. Click Insert > Module www.bluepecan.co.uk
  • 4. • A function is defined with a name (for the function) and if necessary between 1 and 60 arguments. For example the Excel worksheet function VLookup has 4 arguments. www.bluepecan.co.uk
  • 5. A func tio n with no arg ume nts • Several VBA functions such as rand() have no arguments. In the same way you can create custom functions that have no arguments. The following function will display the path and filename of the active workbook. www.bluepecan.co.uk
  • 6. Function File() File = ActiveWorkbook.FullName End Function • Notice the function starts and ends with ‘Function’ rather than sub. www.bluepecan.co.uk
  • 7. • Enter =File() into a worksheet to see the result. or • Click on fx (Insert Function) and open the User Defined category to see your function listed here www.bluepecan.co.uk
  • 8. • The next function displays the username (as set in Tools | Options | General) Function User() User = Application.username End Function www.bluepecan.co.uk
  • 9. A Cus to m Func tio ns with Arg ume nts • The following function simply calculates a value plus VAT. In an empty worksheet create a column of prices. • Then switch to the VBE environment and in a module create the following custom function. Notice that with this function you need to place arguments in the brackets after the function name. • The sales argument will require you to select the cell containing the sales value for which you wish to add the VAT to. www.bluepecan.co.uk
  • 10. Function vat(sales) vat = sales * 1.15 End Function • Use the VAT function to calculate the VAT inclusive value in your list of prices www.bluepecan.co.uk
  • 11. • We could also add a markup value as part of our function by adding a second argument. www.bluepecan.co.uk
  • 12. Function retail(sales, markup) retail = sales * (markup + 1) * 1.15 End Function www.bluepecan.co.uk
  • 13. • Enter a markup percentage on your worksheet and refer to this value in the second argument of the function (separated from the first by a comma). • You can always use the functions argument dialogue box to enter cell references or values. www.bluepecan.co.uk
  • 14. • The following function calculates the amount of time that has elapsed between a start time and the end time. • The function also works for times over two separate days, in other words when the start time is greater than the end time. www.bluepecan.co.uk
  • 15. Function CalTime(StartTime, EndTime) If StartTime > EndTime Then CalTime = EndTime - StartTime + 1 Else CalTime = EndTime - StartTime End If End Function www.bluepecan.co.uk
  • 16. • See this Excel training tutorial on the Blue Pecan website www.bluepecan.co.uk