gpt4 book ai didi

string - 在excel vba中的给定索引处删除字符串的元素

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

如何删除excel vba中给定索引处的字符串元素?我当前的代码如下所示:

Private Sub RemovePeriods_Click()
Dim i As Integer
Dim Cutoff As Integer

For i = 0 To 14283

Cutoff = InStr(1, Range("K6").Offset(i, 0).Value, ".", vbTextCompare)
If Cutoff > 0 Then

End If
Next i
End Sub

因此,在最后一个 if 语句中,我想编写代码来删除由 cutoff 指定的索引处的句点。我该怎么做呢?

提前致谢!

最佳答案

这将满足您的要求。试试这个,让我知道。

Private Sub RemovePeriods_Click()

Dim i As Integer
Dim Cutoff As Integer
Dim rngData As Range
Dim strToReplace As String

'Assign String to replace here
strToReplace = "."

For i = 0 To 14283
'Assign the cell to Range
Set rngData = Range("K6").Offset(i, 0)
Cutoff = InStr(1, rngData, strToReplace, vbTextCompare)
If Cutoff > 0 Then
'Apply Replace formula
rngData = WorksheetFunction.Replace(rngData, Cutoff, Len(strToReplace), "")
End If
Next i

Set rngData = Nothing

End Sub

关于string - 在excel vba中的给定索引处删除字符串的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26413269/

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