返回列表 上一主題 發帖

[發問] VBA 程式碼簡化。

本帖最後由 准提部林 於 2015-11-9 14:49 編輯

If ([T5] + [Q6]) Mod [R6] > 0 Then
  Cells(([T5] + [Q6]) Mod [R6] + 6, 1).Interior.ColorIndex = 8 'A欄的T5期數標示底色
Else
  Cells([R6] + 6, 1).Interior.ColorIndex = 8
End If

改成:
N = ([T5] + [Q6]) Mod [R6]
If N = 0 Then N = [R6]
Cells(N + 6, 1).Interior.ColorIndex = 8
N = ([T5] + [Q6]) Mod [R6] '再重置N,讓下方引用

TOP

If ([T5] + [Q6]) Mod [R6] = 0 Then
∼∼
∼∼
End If

改成:
If N = 0 Then '這是延續上方的值(以下同) 
  Cells([R6] + 6, j - 8).Interior.ColorIndex = 8
  Cells([R6] + 6, j).Interior.ColorIndex = 37
  X = [Q6]
Else
  For k = 0 To Int(([R6] - N) / [Q6])
    Cells(N + 6 + [Q6] * k, j - 8).Interior.ColorIndex = 8
    Cells(N + 6 + [Q6] * k, j).Interior.ColorIndex = 37
  Next k
  X = ([R6] - ([R6] - N) Mod [Q6] + [Q6]) Mod [R6]
End If
 
With Cells(X + 6, j - 8)
   .Interior.ColorIndex = 8: .Font.ColorIndex = 7: .Font.FontStyle = "粗體"
End With
With Cells(X + 6, j)
   .Interior.ColorIndex = 37: .Font.ColorIndex = 7: .Font.FontStyle = "粗體"
End With

TOP

        靜思自在 : 口說好話、心想好意、身行好事。
返回列表 上一主題