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

For i = 1 To lastRow '循环检查每个单元格
    If InStr(Cells(i, "H").Value, "C") > 0 Then '判断是否包含'C'
        Dim str As String
        str = Cells(i, "H").Value
        Dim numIndex As Integer
        numIndex = InStr(str, "C") + 1 '获取数字的起始位置
        Dim numStr As String
        numStr = Mid(str, numIndex, Len(str) - numIndex + 1) '获取数字字符串
        If IsNumeric(numStr) Then '判断数字字符串是否为数字
            Dim cutStr As String
            cutStr = Right(str, Len(str) - numIndex) '获取需要剪切的字符串
            Cells(i, "H").Value = Left(str, numIndex - 1) '将剪切后的字符串从原单元格中删除
            Cells(i, "L").Value = cutStr '将剪切后的字符串黏贴到L列相应的单元格中
        End If
    End If
Next i

End Sub

Excel VBA: 从H列提取“C+数字”并粘贴到L列

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

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