Visual Basic for Applications (VBA) allows you to incorporate powerfull code into your standard Microsoft Office Documents. These tutorials will teach you the ins and outs of how to use VBA within excel from nifty tricks to fully fledged mutli-user systems.
All our tutorial samples are free however if you appreciate our work and would like to make a voluntary donation then please do.
Download the samples for this series for free!
- VBA 2010 – 001: Creating a Macro
- VBA 2010 – 002: Referencing Ranges
- VBA 2010 – 003: Referencing With Cells
- VBA 2010 – 004: Hiding Rows and Columns
- VBA 2010 – 005: Referencing Selections
- VBA 2010 – 006: Variables
- VBA 2010 – 007: Numerical Operations
- VBA 2010 – 008: Strings
- VBA 2010 – 009: String Methods
- VBA 2010 – 010: Dates and Time
- VBA 2010 – 011: Date and Time Methods
- VBA 2010 – 012: Booleans
- VBA 2010 – 013: IF Statements
- VBA 2010 – 014: IF ELSE Statements
- VBA 2010 – 015: Nested IF Statements
- VBA 2010 – 016: Select Case (Switch)
- VBA 2010 – 017: AND + OR
- VBA 2010 – 018: Arrays
- VBA 2010 – 019: 3D Arrays
- VBA 2010 – 020: FOR Loops
- VBA 2010 – 021: Looping Through Arrays
- VBA 2010 – 022: Looping Through Objects
- VBA 2010 – 023: Nested For Loops
- VBA 2010 – 024: Looping 3D Arrays
- VBA 2010 – 025: Do While Loops
- VBA 2010 – 026: Do Until Loop
- VBA 2010 – 027: Nesting While/Until
- VBA 2010 – 028: Speeding up Loops
- VBA 2010 – 029: Calling Functions
- VBA 2010 – 030: Variable Scope
- VBA 2010 – 031: Passing Variables
- VBA 2010 – 032: Passing Multiple Variables
- VBA 2010 – 033: Returning Values
- VBA 2010 – 034: Passing Variables ByRef
- VBA 2010 – 035: Selection Change
- VBA 2010 – 036: Double Click
- VBA 2010 – 037: Worksheet Change
- VBA 2010 – 038: Worksheet Activation
- VBA 2010 – 039: Worksheet Open
- VBA 2010 – 040: Worksheet Close
- VBA 2010 – 041: Before Save
- VBA 2010 – 042: Creating a Userform
- VBA 2010 – 043: Command Buttons
- VBA 2010 – 044: Text Box
- VBA 2010 – 045: Option Buttons
- VBA 2010 – 046: Check Box
- VBA 2010 – 047: List Boxes 1
- VBA 2010 – 048: List Boxes 2
- VBA 2010 – 049: Frames
- VBA 2010 – 050: Multipage
- VBA 2010 – 051: Calendars
- VBA 2010 – 052: Backgrounds
- VBA 2010 – 053: Events
- VBA 2010 – 054: Command Buttons
- VBA 2010 – 055: Text Box
- VBA 2010 – 056: Drop Down Box
- VBA 2010 – 057: Spin Buttons
- VBA 2010 – 058: Check Box
- VBA 2010 – 059: Option Button
- VBA 2010 – 060: List Box
- VBA 2010 – 061: Sending Emails
- VBA 2010 – 062: Emails with Attachments
- VBA 2010 – 063: Shell Command
- VBA 2010 – 064: SendKeys
- VBA 2010 – 065: Defining Properties
- VBA 2010 – 066: Get and Let
- VBA 2010 – 067: Functions and Subs
- VBA 2010 – 068: Initialize & Terminate
- VBA 2010 – 069: Error Handling
- VBA 2010 – 070: Global Variables
- VBA 2010 – 071: ADODB
- VBA 2010 – 072: Recordsets
- VBA 2010 – 073: SQL WHERE
- VBA 2010 – 074: Multiple Records
- VBA 2010 – 075: SQL INSERT
- VBA 2010 – 076: SQL DELETE
- VBA 2010 – 077: SQL UPDATE
- VBA 2010 – 078: SQL Sanitation
- VBA 2010 – 079: SQL AND
- VBA 2010 – 080: SQL OR
- VBA 2010 – 081: SQL Numeric Parameters
- VBA 2010 – 082: SQL Date Parameters
- VBA 2010 – 083: SQL BETWEEN
- VBA 2010 – 084: SQL ORDER BY
- VBA 2010 – 085: SQL TOP
- VBA 2010 – 086: SQL COUNT & SUM
- VBA 2010 – 087: SQL GROUP BY
- VBA 2010 – 088: SQL JOINS
- VBA 2010 – 089: SQL DISTINCT
- VBA 2010 – 090: SQL Insertion
- VBA 2010 – 091: SQL Parameters
- VBA 2010 – 092: SQL Multiple Parameters
- VBA 2010 – 093: ADODB Spreadsheet Connection
- VBA 2010 – 094: Create a New Workbook
- VBA 2010 – 095: Open a Workbook
- VBA 2010 – 096: FileSystemObjects
- VBA 2010 – 097: Open all files in a Folder
- VBA 2010 – 098: ADODB +FSO = Amazing
- VBA 2010 – 099: GetOpenFilename
- VBA 2010 – 100: Creating Formulas
- VBA 2010 – 101: Creating Add-Ins
- VBA 2010 – 102: Passwording a Project
- VBA 2010 – 103: Calling Add-In Functions
- VBA 2010 – 104: Referencing Add-In Sheets
- VBA 2010 – 105: Add-In Events
- VBA 2010 – 106: Custom Right Click Menu
- VBA 2010 – 107: Right Click Sub-Menu
- VBA 2010 – 108: Right Click Menu Add-In
- VBA 2010 – 109: Customising all Menus
- VBA 2010 – 110: Read Input From Text File
- VBA 2010 – 111: Adding Data to a Text File
- VBA 2010 – 112: Creating a text file
- VBA 2010 – 113: Creating a HTML file
- VBA 2010 – 114: Creating a SQL file
Recommended Reading
Both the below books by John Walkenbach are fantastic books and he is a brilliant author, I would recommend picking one of these books up even if just for a reference. I have read power programming cover to cover and it is easy to follow and is a must have for any serious VBA programmer.
If you have read any books and feel they are worth recommending then please post about them on our Forum.
Hi,
I went through all your macro videos and it was very helpful. Now I’m trying to write a macro, which will run once the batch job is completed. I am also triggering a batch job using the same macro. But as the batch job takes some time to run i want the macro to wait till the batch is completed. Could you please help me in this?
Thanks.
only thing i can think of is that you get the batch file to generate a temp txt file once its completed that the vba then identifies as being there and then does what it needs to and deletes the file. Its not the best though and vba not having threads is going to make it messy.
Hi Matt,
I was doing this piece of code:
For Each cel In Target.Cells
cel.Interior.ColorIndex = cel.Interior.ColorIndex + 1
Next cel
but this give me error: subscript out of range (in Excel 2013). This is exactly the same code as your tutorial 35.
Please suggest.
I get the error in the line where i’m trying to update the colorindex
Dear Matt,
Your videos are great mate and thanks for sharing with us. I was following videos couple of weeks now to master the VBA.
I got a question for you in the VBA tutorial 41 and I having a issue when saving the actual new workbook excel file for your particular code. Further, in my workbook it doesn’t allow be to save macro enable workbook for this code for the newly opened workbook. (however, I have already selected the option to run all the macros via the Developer>>Macro Security option). Further, when I try to save in “Save as” the dialog box, I couldn’t find the “Macro Enable workbook” . kindly please help
Waz
Hello Matt,
I went through your tutorial on VBA and i must admit that these are the best i have ever seen. It has helped me a lot in understanding the concepts.
I had a query if you can help me with.
I have a folder inside which i have several notepads. I want to search and replace any string for all of those notepads without having to individually open each of those.Would you able to suggest me a macro as to how can we take inputs from the user as to which strings he wants to replace and also what he wants to replace that with and run a macro to do the same.
Cheers!!!
Carl
Hi Matty, I am new to VBA and hope that you can help me with my PO-Template – Excel VBA which I copied below:
‘What I want is for any user or myself to be able to
‘Open the PO-Template;
‘Generate a new PO number;
‘Complete the PO-Template with purchase order information in each required cell;
‘Send the information from the designated cells to the PO-Log;
‘Print the PO-Template;
‘Save a copy in both .pdf and .xlsx formats in the parent folder \PO-2015\;
‘Clear all the cells;
‘Keep the PO-Template in .xlsm format to start all over again.
Once I completed my PO-Template, I looked at my files and deleted the .xlsx file thinking that it was not the one I needed and kept the .xlsm file. I no longer had my macros and had to start all over again! This is what I could remember. I need help putting it together in the right order and with only one or two buttons.
Sub NextPO()
‘This allows the PO-Template to change PO number when clicked
‘The cells are cleared to create a new PO
Range(“B4″).Value = Range(“B4″).Value + 1
Range(“B5″) = Date
Range(“A11:D23″) = “”
Range(“B6″) = “”
Range(“B7″) = “”
Range(“B8″) = “”
Range(“D24″) = “”
Range(“D26″) = “”
Range(“D28″) = “”
ActiveWorkbook.SaveAs “PO-Template.xlsm”
End Sub
Sub POReport()
‘Once the PO-Template is filled, copy the information from the cells PO number (B4), Project Name (B6) and Supplier (B7) to the PO-Log
Dim myFile As String, lastRow As Long
myFile = “C:\Users\Brisson\Documents\Database\” & Sheets(“PO-Template”).Range(“B4″) & “-” & Sheets(“PO-Template”).Range(“B6″) & “-” & Sheets(“PO-Template”).Range(“B7″) & “.pdf”
lastRow = Sheets(“PO-Log”).UsedRange.SpecialCells(xlCellTypeLastCell).Row + 1
‘Transfer data to Log
Sheets(“PO-Log”).Cells(lastRow, 1) = Sheets(“PO-Template”).Range(“B4″)
Sheets(“PO-Log”).Cells(lastRow, 2) = Sheets(“PO-Template”).Range(“B6″)
Sheets(“PO-Log”).Cells(lastRow, 3) = Sheets(“PO-Template”).Range(“B7″)
Sheets(“PO-Log”).Cells(lastRow, 4) = Now
Sheets(“PO-Log”).Hyperlinks.Add Anchor:=Sheets(“PO-Log”).Cells(lastRow, 6), Address:=myFile, TextToDisplay:=myFile
‘Saves the PO (PO number (B4), the Project Name (B6) and the Supplier (B7)) in PDF format
‘The syntax below was working and now it does not save the document in .pdf format in the \PO-2015\ folder.
Sheets(“PO-Template”).ExportAsFixedFormat Type:=xlTypePDF, Filename:=myFile
‘Saves the PO (PO number (B4), the Project Name (B6) and the Supplier (B7)) in xlsx format
ActiveWorkbook.SaveAs “C:\Users\Brisson\Documents\Database\PO-2015\” & Sheets(“PO-Template”).Range(“B4″) & “-” & Sheets(“PO-Template”).Range(“B6″) & “-” & Sheets(“PO-Template”).Range(“B7″) & “.xlsx”, FileFormat:=51
‘ActiveWorkbook.Close
Application.DisplayAlerts = True
End Sub
I am not sure I have everything in the right order. If you wish to see my PO-Template, I can send it to you. Thank you so much for the time you will take to help me with this. I will be happy to give you a donation! Rachel
Jon:
I see the PROPERTIES & METHODS for an object at:
https://msdn.microsoft.com/en-us/library/office/ff193284.aspx.
However, the following statement I coded tells me that “Worksheets” is an object within “Workbooks” :
Application.Workbooks(1).Worksheets(3).Range(“B8″).Value = 138
But when I click on “Workbooks Members” at the (above) link it does not show that “Worksheets” is contained in “Workbooks”…how come?
Thanks,
Dan
Great work Matt.
Dear Mathew,
your videos are great. Thank you.
A question please:
I am writing a connection to an Excell file using VBA,
Set cn = CreateObject(“ADODB.Connection”)
With cn
.Provider = “Microsoft.ACE.OLEDB.12.0″
.ConnectionString = “Data Source=” & basesFile & “;” & _
“Extended Properties=””Excel 12.0 Xml;HDR=YES””;”
.Open
End With
runs good – however can not read data if the file is in use, it needs to be either closed or shared. Can it be read when it is in use by another user (working on a network).?
appreciate your reply,
Thanks,
Ronit