写一个excel的vba逻辑是检查H列的数据不限字符数找到单元格中C+数字的字符并删除其后面的字符
Sub CheckAndRemove() Dim lastRow As Long Dim cell As Range Dim str As String Dim numPos As Long
'获取最后一行
lastRow = ActiveSheet.Cells(Rows.Count, "H").End(xlUp).Row
'循环检查每个单元格
For Each cell In Range("H2:H" & lastRow)
str = cell.Value
numPos = InStr(str, "C")
If numPos > 0 And IsNumeric(Mid(str, numPos + 1, 1)) Then
'找到"C+数字"的字符并删除其后面的字符
cell.Value = Left(str, numPos + 1)
End If
Next cell
End Sub
原文地址: https://www.cveoy.top/t/topic/bjrd 著作权归作者所有。请勿转载和采集!