返回列表 上一主題 發帖

VBA_A期數在B期數的對應值有再顯示於C期數的儲存格時,則各標示底色之語法。

回復 2# Airman


   VBA_列39~列59增修_v1.rar (27.66 KB)

TOP

回復 6# Airman


If .[T5] > .Range("R" & b.Row) And .Range("R" & b.Row) > 0 Then
  RW = Array(.[T5], b(1, -1), b(1, -1) + .[T3])
  For y = 1 To 3: Set UR(y) = .[J:P].Rows(RW(y - 1) + 6).Cells: Next y
  For z = 1 To 7
    Set R(1) = UR(1)(z): Set R(2) = Nothing: Set R(3) = Nothing
    Set R(2) = UR(2).Find(R(1), Lookat:=xlWhole)
    If Not R(2) Is Nothing Then
     Set R(2) = UR(2)(z)
     Set R(3) = UR(3).Find(R(2), Lookat:=xlWhole)
    End If
    If Not R(3) Is Nothing Then
     For y = 1 To 3
      R(y).Interior.ColorIndex = Array(40, 39, 45, 4, 38, 37, 8)(z - 1)
     Next
     Set R(2) = UR(2).Find(R(1), Lookat:=xlWhole)
      For y = 1 To 2
       R(y).Font.ColorIndex = 7   '設定文字
       R(y).Font.FontStyle = "粗體"
     Next y
    End If
  Next z
End If

這種密密麻麻的文字描述, 程式碼新舊混合, 實在不太習慣, 太花時間及眼力!!!

TOP

回復 9# Airman

修改部份大致都對,其實自己多測幾次去漸次修改,也可以的!!!

For z = 1 To 7
  Set R(1) = UR(1)(z): Set R(2) = Nothing: Set R(3) = Nothing
  If UR(2)(z) = R(1) Then
    Set R(2) = UR(2)(z) '同欄
    Set R(3) = UR(3).Find(R(2), Lookat:=xlWhole) '不同欄
    'If UR(3)(z) = R(1) Then Set R(3) = UR(3)(z) '同欄
  End If
  If Not R(3) Is Nothing Then
    For y = 1 To 3
      R(y).Interior.ColorIndex = Array(40, 39, 45, 4, 38, 37, 8)(z - 1)
    Next
    For y = 1 To 2
      R(y).Font.ColorIndex = 7   '設定文字
      R(y).Font.FontStyle = "粗體"
    Next y
  End If
Next z

TOP

        靜思自在 : 好事要提得起,是非要放得下,成就別人即是成就自己。
返回列表 上一主題