返回列表 上一主題 發帖

可否請各位先進幫我簡化代碼

試試這樣(我沒有測試)
但是如果要寫10000 個cell,不會快很多.
  1. Private Sub jump123()
  2. Application.Calculation = xlCalculationManual
  3. Application.ScreenUpdating = False
  4. For a = 2 To 10000
  5.   If Cells(a, 1) = "" Then Exit For
  6.     s = Left(Cells(a, 4), 6)
  7.     b = False
  8.     If s = "201106" Then
  9.         b = True
  10.         Cells(a, 5) = "A"
  11.     ElseIf s = "201101" Then
  12.         b = True
  13.         Cells(a, 5) = "B"
  14.     ElseIf s = "201111" Then
  15.         b = True
  16.         Cells(a, 5) = "C"
  17.     ElseIf s = "201102" Then
  18.         b = True
  19.         Cells(a, 5) = "D"
  20.     ElseIf s = "201127" Then
  21.         b = True
  22.         Cells(a, 5) = "E"
  23.     End If
  24.     If Not (b) Then
  25.         k1 = Left(s, 2)
  26.         If k1 = "11" Then
  27.             k2 = Mid(s, 3, 2)
  28.             If k2 >= "01" And k2 <= "17" Then
  29.                 Cells(a, 5) = Chr(69 + Val(k2))
  30.             ElseIf k2 >= "18" And k2 <= "20" Then
  31.                 Cells(a, 5) = Chr(70 + Val(k2))
  32.             End If
  33.         End If
  34.     End If
  35.    Next a
  36. Application.Calculation = xlCalculationAutomatic
  37. Application.ScreenUpdating = True
  38. End Sub
複製代碼
懂得發問,答案就會在其中

今日の一秒は  明日にない
http://kimbalko-chi.blogspot.com
http://kimbalko.blogspot.com

TOP

        靜思自在 : 難行能行,難捨能捨,難為能為,才能昇華自我的人格。
返回列表 上一主題