VBA Substrings

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Remarks

VBA has built-in functions for extracting specific parts of strings, including:

  • Left/Left$
  • Right/Right$
  • Mid/Mid$
  • Trim/Trim$

To avoid implicit type conversion onverhead (and therefore for better performance), use the $-suffixed version of the function when a string variable is passed to the function, and/or if the result of the function is assigned to a string variable.

Passing a Null parameter value to a $-suffixed function will raise a runtime error ("invalid use of null") - this is especially relevant for code involving a database.



Got any VBA Question?