Adding error handlers to your code is very import to enable you to fix errors that come up from users. This allows them to easily pass the info on so that the developer can fix. Without error handlers, the code will either skip the errors or just bring up a confusing pop of that the… Continue reading Understanding On Error Resume next
Category: excel
ByRef vs ByVal
When passing arguments to a procedure (sub or function) the default will be 'byRef' in Excel VBA, thus you don't have to write 'byRef' before the variable. If you want to pass ByVal you have to explicitly write 'ByVal' before the variable. When using ByVal you are only passing a copy of the argument to… Continue reading ByRef vs ByVal
Run a Macro at a Specific Time
Sub ImportModules() Debug.Print "test" End Sub Private Sub Workbook_Open() Application.OnTime Now + TimeValue("00:00:01"), "domeprog.ThisWorkbook.ImportModules" End Sub The code above will run the macro called 'ImportModules' one second after the workbook is opened. If the macro is located in a class module or in ThisWorkbook class, then you will need to call out the library +… Continue reading Run a Macro at a Specific Time
Add items to a UserForm ComboBox
When you don' t want the user to input their own value, set the combobox style to 2. This will force the user to pick from the list of items. The default style is 0, it will behaves as a drop-down combo box or a region to type any value. ComboBox54NozzleSize.sytle = 2 '0=fmStyleDropDownCombo '2=fmStyleDropDownList… Continue reading Add items to a UserForm ComboBox
Public Variables in VBA
USE CAUTION! Any time you declare a variable as public it is important to understand all the consequences and how they behave. In order to make a variable public it has to have the keyword 'Public' rather than 'dim'. It also has to be declared in a module before the first procedure declaration. It does… Continue reading Public Variables in VBA
Check If Each Input Box is filled
Many times you don't want a user to proceed until all input boxes are filled. To solve this you can loop through each control with a For Each statement. For Each will be especially useful when you there are many controls and you don't want to reference each name individually. The examples below show how… Continue reading Check If Each Input Box is filled
Clear All Check Boxes In Excel VBA Userform
This example uses a for each loop so that each check box name does not have to be explicitly written out. This is useful when you are adding more control and limit the amount of code you are writing. Better Method Dim ctrl As Control Sub ClearAllButton_Click() For Each ctrl In exportFilesUF.Controls If TypeName(ctrl) =… Continue reading Clear All Check Boxes In Excel VBA Userform
Compile Bill of Materials and Remove Duplicates
This example builds upon the methods of finding duplicate data. See https://pearlsnake.com/2019/06/20/find-and-delete-rows-with-duplicate-data/ In order for a row to be complied, Column A, E and K have to match the data in other rows. After running the example the data was been reduced from 35 rows to 30 rows. This helps purchasing departments so they don't… Continue reading Compile Bill of Materials and Remove Duplicates
Find and Delete Rows With Duplicate Data
This code will use the collection object to quickly determine if data is a duplicate. It uses the .add method and will return an error if the data is already in the collection and wont be added. We can also use .count method to see if that item was added to the collection or not.… Continue reading Find and Delete Rows With Duplicate Data