在excel vba中删除给定索引处的string元素

如何在excel vba中删除给定索引处的string元素? 我目前的代码如下所示:

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