Giter Club home page Giter Club logo

vba-methods's Introduction

vba-methods

Code size

A collection of Subs and Functions to do things in Excel VBA For Microsoft Office 16.

Subs and Functions are saved as .vba files to ensure the repository language is correct. What is the difference? Generally, a Sub does a thing and a Function returns a thing.

How to Contribute

PRs and Issues welcome. Use Issues for questions. Use PRs for new functions. Each file is a function Please remember that beginners will use this code. Add comments as needed.

Conventions

We will try to use VB Coding Standards for consistency. The big picture means to

  • Use verb starts and camelCase for sub and function names. Like "getMoreFood()" and "returnLastCupcake()"
  • Use NounDescripter for variable names.
  • there are a whole bunch of others

How to Use

You can copy and paste functions directly into your Visual Basic Windows.

Generic use of a Sub or Function

Let's assume that you want to incorporate the Sub printa(), Sub printStr(myStr), and Function getNextInt(myInt) in another Sub. Of course, this is a contrived example.

First, save your project with the new subs and/or functions in a Module

Sub printa()
   Debug.Print("a") 'prints a in the Immediate Window
End Sub
Sub printStr(myStr As String)
   Debug.Print(myStr) 'prints the passed String in the Immediate Window
End Sub

Function getNextInt(myInt As Integer)
  getNextInt = myInt + 1 ' returns the next Integer
End Function

Then, you can call it in your other Sub

Sub doOtherSub()
   Call printa
   Call printStr("I like Cupcakes")
   
   Debug.Print(getNextInt(4)) ' prints 5
   
   'You can also Dim and use variables
   Dim smyStrVar As String, imyIntVar As Integer
   smyStrVar = "Do you like cupcakes?"
   imyIntVar = 12
   
   Call printStr(smyStrVar)
   Debug.Print(getNextInt(imyIntVar)) 'prints 13
   
   ' You can write to variables with functions
   Dim imyNewInt As Integer
   imyNewInt = getNextInti(myIntVar) 'now, imyNewInt is 13
   
End Sub

vba-methods's People

Contributors

monkeywithacupcake avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.