Sub cutSecondEnglishChar()

Dim lastRow As Long
lastRow = ActiveSheet.Cells(Rows.Count, "H").End(xlUp).Row '获取最后一行

For i = 1 To lastRow
    If IsEmpty(Cells(i, 8)) = False Then '如果H列单元格不为空
        Dim str As String
        str = Cells(i, 8).Value '获取H列单元格的值
        Dim j As Integer
        j = 1
        Do While j <= Len(str) '循环遍历字符串
            If IsNumeric(Mid(str, j, 1)) = False And Asc(Mid(str, j, 1)) >= 65 And Asc(Mid(str, j, 1)) <= 122 Then '如果是英文字母
                Dim k As Integer
                k = j + 1 '找到第二个英文字母
                Do While k <= Len(str)
                    If IsNumeric(Mid(str, k, 1)) = False And Asc(Mid(str, k, 1)) >= 65 And Asc(Mid(str, k, 1)) <= 122 Then
                        Exit Do
                    End If
                    k = k + 1
                Loop
                If k <= Len(str) Then '找到第二个英文字母
                    Cells(i, 10).Value = Mid(str, k, 1) '将第二个英文字母剪切到J列
                    Cells(i, 8).Value = Replace(str, Cells(i, 10).Value, "", 1, 1) '将H列单元格中的第二个英文字母删除
                End If
            End If
            j = j + 1
        Loop
    End If
Next i

End Sub


原文地址: https://www.cveoy.top/t/topic/mKMU 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录