gpt4 book ai didi

excel - VBA 公式在第二个空格后删除所有内容

转载 作者:行者123 更新时间:2023-12-04 22:28:10 25 4
gpt4 key购买 nike

我试图从 D 列复制到 E 列每行的前两个单词,但仍然找不到错误在哪里....

Range("E1:E" & lLastRow).Formula = "=LEFT(D1,FIND("" "",D1,FIND("" "",D1)+1)-1)"

最佳答案

另一种选择,而不是使用公式,您可以使用 Split功能。

代码

Dim i As Long, LastRow As Long
Dim WordsArr As Variant

' loop through rows
For i = 1 To LastRow
WordsArr = Split(Range("D" & i).Value, " ") ' use Split and space to read cell words to array

If UBound(WordsArr) >= 1 Then ' make sure the cell contents is at least 2 words
Range("E" & i).Value = WordsArr(0) & " " & WordsArr(1) ' insert only the first 2 words

Else ' in case there are less than 2 words
' do someting....

End If
Next i

End Sub

关于excel - VBA 公式在第二个空格后删除所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55788962/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com