Excel VBA: 删除H列单元格中第二个英文字母
Sub DeleteSecondLetter() Dim LastRow As Long Dim i As Long Dim CellText As String Dim SecondLetter As String
LastRow = Cells(Rows.Count, "H").End(xlUp).Row
For i = 1 To LastRow
CellText = Cells(i, "H").Value
If CellText Like '*[a-zA-Z][a-zA-Z]*' Then
SecondLetter = Mid(CellText, 2, 1)
Cells(i, "H").Value = Replace(CellText, SecondLetter, "", 2, 1)
End If
Next i
End Sub
说明:
- 首先定义了变量LastRow,用于存储H列最后一个单元格的行号。
- 使用For循环逐行遍历H列的单元格。
- 使用Like运算符检查单元格的文本是否包含至少两个英文字母。
- 如果是,则使用Mid函数找到第二个英文字母,并使用Replace函数将其从单元格中删除。
- 代码执行完毕后,H列中所有符合条件的单元格中的第二个英文字母都被删除了。
原文地址: https://www.cveoy.top/t/topic/mKTx 著作权归作者所有。请勿转载和采集!