Reputation: 25272
I guess the title is quite clear. I tried the below solutions, without success.
My function works great with Strings
, but not with cells
.
Any clue very welcome.
Function nbLeadingSpaces(str As Variant) As Integer
Dim trimmed As String
trimmed = LTrim(str)
'works with strings, not with cells
nbLeadingSpaces = InStr(1, str, Left(trimmed, 1), vbTextCompare) - 1
'same issue
'nbLeadingSpaces = Len(str) - Len(LTrim(str))
End Function
I need this in order to do stuff based on a kind of text outline where the number of leading spaces will show if a row is a main row or sub row (several levels). VBA seems to automatically TRIM the cell contents 8-/
Sorry to all, I am stupid (at least sometimes). There WERE no spaces in front of those cells, but an indent :-)
Problem solved then, I can just get the rng.IndentLevel
and that's it.
Anyway all your remarks help me reanalyze the issue, and I will leave this question, which might help another lost mind one day :-)
Upvotes: 1
Views: 965
Reputation: 25272
Sorry to all, I am stupid (at least sometimes). There WERE no spaces in front of those cells, but an indent :-)
Problem solved then, I can just get the rng.IndentLevel
and that's it.
Upvotes: 1