计算Excel单元格中的前导空格(Counting leading spaces in Excel cell)

编程入门 行业动态 更新时间:2024-10-17 05:28:39
计算Excel单元格中的前导空格(Counting leading spaces in Excel cell)

我猜标题很清楚。 我尝试了下面的解决方案,但没有成功。 我的函数对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 Function

Edit

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.

更多推荐

本文发布于:2023-07-04 17:09:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1026964.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:前导   空格   单元格   Excel   cell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!