In this session, the focus is on understanding the 'Right' function in VBA (Visual Basic for Applications). The video addresses the similarities between the Right function in Excel and VBA, demonstrating its application in various examples with different numbers of characters. You will learn how to effectively use this function to extract specific parts of a string from the right-hand side.

What will you learn

  • How to use the Right function in VBA for string manipulation.
  • Understanding the arguments of the Right function: the string and the number of characters.
  • Practical examples of extracting different numbers of characters from strings.
  • Comparison of the Right function in Excel and VBA.
  • Demonstration of results for different inputs and expected outputs.

Takeaway notes

  • The Right function in VBA works similarly to the Right function in Excel.
  • The function syntax is: Right(string, number_of_characters).
  • The first argument is the string from which you want to extract text.
  • The second argument is the number of characters to be extracted from the right-hand side of the given string.
  • Practical examples provided: extracting 2, 5, and 9 characters from different strings ("Microsoft VB script", "MEMS VB SCRIPT", "Microsoft").

Practice questions

  1. What are the two arguments required by the Right function in VBA?
  2. Write the VBA code to extract the last 4 characters from the string "Hello World".
  3. Explain how the Right function in VBA is similar to the Right function in Excel.
  4. Demonstrate a scenario where the Right function is used to extract the last 3 characters from the string "Visual Basic".
  5. If var = "Board Infinity" and you apply Right(var, 7), what will be the output?
  6. What will the Right function return if the number of characters to extract is more than the string length?
  7. Write a VBA code snippet to extract and print the last 6 characters from the string "Data Science".
  8. How would you use the Right function to extract characters from a variable holding the string "Excel VBA"?
  9. Predict the output of Right("Machine Learning", 5).
  10. Create a VBA program that reads a string from the user and prints the last 8 characters.
  11. Explain the result of Right("Advanced Excel", 0).
  12. Write a VBA code to print the last character of the string "Function".
  13. How does the Right function handle white spaces at the end of a string?
  14. In the example var = "Automation", what does Right(var, 4) return?
  15. Write a VBA macro that uses the Right function to extract the last 3 characters from a list of strings in an Excel column.

Mark Lesson Complete (Mastering the Right Function in VBA)