Sub CutAndPaste() Dim lastRow As Long Dim i As Long Dim cellValue As String Dim cutValue As String

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

For i = 1 To lastRow '遍历每一行
    cellValue = ActiveSheet.Range("H" & i).Value '获取H列单元格的值
    If Left(cellValue, 1) = "C" And IsNumeric(Mid(cellValue, 2, 1)) Then '判断是否满足条件
        cutValue = Mid(cellValue, 3) '剪切要粘贴的字符
        ActiveSheet.Range("H" & i).Value = "C" & Mid(cellValue, 2, 1) '将剩余字符填充回原单元格
        ActiveSheet.Range("J" & i).Value = cutValue '粘贴到J列
    End If
Next i

End Sub

Excel VBA: 从 H 列单元格中提取 C+数字 后面的字符并粘贴到 J 列

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

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