Excel宏的性能不佳

用户名

我在vb中为Excel及其工作创建了一个宏,但问题是对于40000行,它的工作速度非常慢(在c2d e7500 @ 2,9 GHz上约为2分钟)。我认为可以更快地完成,但是我不知道如何:)有人可以帮助我吗?

Dim bufor As String
Dim condition As Boolean

    Cells.Find(What:="Month", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
    xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
    , SearchFormat:=False).Activate

    ActiveCell.Offset(1, 0).Range("A1").Select
    ActiveCell.Select

    Do While condition = False
    bufor = Right(ActiveCell.Value, 1)


        If bufor = "1" Then
        ActiveCell.Value = "January"
        ElseIf bufor = "2" Then
        ActiveCell.Value = "February"
        ElseIf bufor = "3" Then
        ActiveCell.Value = "March"
        ElseIf bufor = "4" Then
        ActiveCell.Value = "April"
        ElseIf bufor = "5" Then
        ActiveCell.Value = "May"
        ElseIf bufor = "6" Then
        ActiveCell.Value = "June"
        ElseIf bufor = "7" Then
        ActiveCell.Value = "July"
        ElseIf bufor = "8" Then
       ActiveCell.Value = "August"
       ElseIf bufor = "9" Then
       ActiveCell.Value = "September"
       ElseIf bufor = "10" Then
       ActiveCell.Value = "October"
       ElseIf bufor = "11" Then
       ActiveCell.Value = "November"
     ElseIf bufor = "12" Then
     ActiveCell.Value = "December"
    End If



     ActiveCell.Offset(1, 0).Range("A1").Select
     ActiveCell.Select


    If ActiveCell.Value = "" Then 
    condition = True
    End If

    Loop
amg

在宏的开头使用以下代码

Application.ScreenUpdating = False

并且在代码的结尾不要忘了启用它

Application.ScreenUpdating = True

喜欢

sub Test()

Application.ScreenUpdating = False

 ---- your code------

Application.ScreenUpdating = True

End Sub

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章