EXCLE的两个简单宏脚本

来源:互联网 发布:linux服务器故障排查 编辑:程序博客网 时间:2024/06/07 06:43

最近修改EXCLE,尝试着学习了一下VBA,做一个记录

 

1.U列 值为I的全部删除

 

Sub Macro1()
Dim i As Integer
Dim max As Integer
max = Worksheets("Sheet1").UsedRange.Rows.Count
For i = 2 To max
    If Cells(i, "U").Value = "I" Then
        Rows(i).Delete
        If max = i Then GoTo myend
        i = i - 1
        max = max - 1
    Else
        If max = i Then GoTo myend
   End If
Next i
myend: End Sub

 

2.AM列只保留年

 

Sub Macro1()
    Dim i As Integer
    For i = 2 To 935
        Cells(i, "AM").Value = Int(Cells(i, "AM").Value / 10000)
    Next
End Sub