我猜标题很清楚。 我尝试了下面的解决方案,但没有成功。 我的函数对Strings很好用,但对cells不起作用。 任何线索都非常受欢迎。
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编辑
对不起,我很愚蠢(至少有时候)。 在这些单元格前没有空格 ,但缩进 :-) 那么问题就解决了,我只能得到rng.IndentLevel就是这样。 无论如何,你所有的言论都可以帮助我重新分析这个问题,并且我会留下这个问题,这可能有助于另一天失去理智.-)
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 FunctionEdit
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 :-)
最满意答案
对不起,我很愚蠢(至少有时候)。 在这些单元格前没有空格 ,但缩进 :-) 那么问题就解决了,我只能得到rng.IndentLevel就是这样。
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.
更多推荐
发布评论