VBA & macros
Automate repeat work with macros and VBA code.
- Excel VBA Import From Another Workbook: A Safe GuideTo import a worksheet with VBA, open the source workbook, copy the required worksheet into the workbook containing the macro, and close…
- Excel VBA: How to Include Double Quotes in StringsIn Excel VBA, put two double-quote characters inside a string literal wherever you want the resulting text to contain one double quote.…
- Excel VBA: How to Include Double Quotes in a StringIn Excel VBA, write two double-quote characters inside a string literal wherever you want one actual double quote. For example, message =…
- Excel VBA: Import CSV Data the Right WayTo import a CSV file with Excel VBA, use Workbooks.OpenText to parse it, then copy its values into a worksheet in your…
- Excel VBA: Import a CSV Into a WorksheetTo import a CSV file into an Excel worksheet with VBA, use Application.GetOpenFilename to choose the file, open it with Workbooks.OpenText, and…
- Excel VBA: Import Data From Another Workbook Step by StepTo import data from another workbook with Excel VBA, open the source file, identify its worksheet and range, then assign that range…
- Excel VBA: Check If a String Is NumericIn Excel VBA, use the built-in IsNumeric function to check whether a string can be interpreted as a number: If IsNumeric(value) Then.…
- Excel VBA Import CSV: Methods, Code, and Common IssuesTo import a CSV into an Excel worksheet with VBA, open the file with Workbooks.OpenText, then copy its parsed cells into the…
- Excel VBA If Then GoTo Next Loop? The Safe PatternYes. In Excel VBA, use an If...Then GoTo statement to jump to a label placed immediately before the loop’s Next or Loop…
- Excel VBA If String Equals: Exact and Case-InsensitiveIn Excel VBA, test whether two strings are equal with If firstText = secondText Then. That comparison is case-sensitive by default; use…
- Excel VBA If Not IsDate: Check Dates in Excel CellsIn Excel VBA, use If Not IsDate(value) Then to run code when a value is not recognized as a date or time.…
- Excel VBA: Check Whether a Cell Contains TextTo check whether a cell contains a particular string in Excel VBA, use InStr and test whether its result is greater than…
- Excel VBA: Check Whether an Array Contains a ValueTo check whether a VBA array contains a value, loop through its elements and compare each one with the value you are…
- Excel VBA Hyperlink to Worksheet: A Practical GuideTo make a cell link to another worksheet with VBA, use Hyperlinks.Add and set Address to an empty string and SubAddress to…
- Excel VBA Hyperlink: Add, Edit, and TroubleshootExcel VBA does not have a built-in Hyperlink() function: to create a clickable link in a macro, use the Hyperlinks.Add method. For…
- Excel VBA: Hide a Worksheet and Control VisibilityTo hide a worksheet with VBA, set its Visible property to xlSheetHidden: ThisWorkbook.Worksheets("Sheet1").Visible = xlSheetHidden. To keep it out of Excel’s normal…
- Excel VBA: Highlight Cells in an Array LoopTo highlight worksheet cells while looping through an array in Excel VBA, read a range into an array, test each array value,…
- Excel VBA: Hide a Column RangeTo hide a range of columns with Excel VBA, set its Hidden property to True: use Columns("B:D").Hidden = True to hide columns…
- Excel VBA: How to Hide a Workbook WindowTo hide the active workbook window with VBA, set its Visible property to False, for example: ThisWorkbook.Windows(1).Visible = False. This hides the…
- Excel VBA: Hide a Range of Cells or RowsIn Excel VBA, you can hide the entire rows or columns that contain a range, but you cannot hide just an arbitrary…
- Excel VBA Hidden Worksheets: Hide and Unhide SheetsIn Excel VBA, hide a worksheet by setting its Visible property to xlSheetHidden or xlSheetVeryHidden; set it to xlSheetVisible to show it…
- Excel VBA Hex String: Convert Numbers to HexadecimalIn Excel VBA, use the Hex function to turn a number into a hexadecimal string: Hex(255) returns FF. The result has no…
- Excel VBA: Hide a Column Based on a Cell ValueYes. In Excel for Microsoft 365 on Windows, VBA can set a column’s Hidden property according to the value in a cell.…
- Excel VBA GoTo: How Labels and Errors WorkIn Excel VBA, GoTo is a statement—not a function—that transfers execution to a labeled line in the same procedure. It is also…
- Excel VBA Hard-Coded Arrays: Syntax, Types, and ExamplesYes. In Excel VBA, you can hard-code a list of values with the Array function and assign it to a Variant, such…
- Excel VBA Hex Function: Convert Numbers to HexIn Excel VBA, Hex(number) converts a numeric value to a hexadecimal text string: for example, Hex(255) returns FF. It does not add…
- Excel VBA Get Year From Date: Code, Dates, and ErrorsTo get the year from a date in Excel VBA, use the built-in Year function: Year(dateValue). For example, Year(Worksheets("Sheet1").Range("A2").Value) returns the year…
- Excel VBA Global Array Example: Scope, Setup, and UseIn Excel VBA, declare a shared array with a Public statement at the top of a standard module, outside any procedure. For…
- Excel VBA Global Functions: Scope and How to Create OneIn Excel VBA, a global function is usually a Public Function declared in a standard module, making it callable from other modules…
- Excel VBA Get Worksheet Index: Methods and ExamplesIn Excel VBA, read a worksheet’s Index property to get its position in the workbook’s sheet-tab order: for example, ThisWorkbook.Worksheets("Data").Index. The number…