写一个excel的vba逻辑是检查H列的数据不限字符数找到单元格中符合C+数字的字符并删除其后面的字符
Sub CheckAndRemove() Dim lastRow As Long Dim i As Long
lastRow = ActiveSheet.Cells(Rows.Count, "H").End(xlUp).Row
For i = 1 To lastRow
If InStr(1, Range("H" & i).Value, "C") > 0 Then '检查是否存在"C"
If IsNumeric(Mid(Range("H" & i).Value, InStr(1, Range("H" & i).Value, "C") + 1, 1)) Then '检查"C"后面是否为数字
Range("H" & i).Value = Left(Range("H" & i).Value, InStr(1, Range("H" & i).Value, "C") + 1) '删除"C"后面的字符
End If
End If
Next i
End Sub
原文地址: https://www.cveoy.top/t/topic/bjqz 著作权归作者所有。请勿转载和采集!