Search code examples
vbaexcel

How to count the number of empty spaces in front of a String in VBA?


I have a YAML file which I am reading using VBA Excel plugin. I am getting a String of each line. I need to count the number of empty spaces in the front of the first line so that it will be a marker to find the next key. Let me know how to do that.


Solution

  • Option Explicit
    
    Function empty_spaces(str_input)
        empty_spaces = Len(str_input) - Len(LTrim(str_input))
    End Function
    

    harun24hr, your answer does not work with " My String " and similar.