返回列表 上一主題 發帖

[發問] 關於選取儲存格後,該列範圍變色,出現位移。

本帖最後由 quickfixer 於 2021-9-5 20:57 編輯

回復 6# av8d


    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim xA As Range, xR As Range
Cells.Interior.Pattern = 0
If Target.Column = 3 Then
    Set xA = [A4:G1000]
    If Intersect(xA, Target) Is Nothing Then Exit Sub
    For Each xR In xA.Rows
        If Not Intersect(xR, Target) Is Nothing Then
            If Cells(xR.Row, 3) <> "" Then
                xR.Interior.Color = RGB(240, 255, 240)
            Else
                Cells(xR.Row, 3).Interior.Color = RGB(200, 200, 240)
            End If
        End If
    Next
End If
End Sub

TOP

本帖最後由 quickfixer 於 2021-9-6 01:05 編輯

回復 9# av8d


    我使用samwang的程式碼,在#7改寫的,用你的說明操作,沒問題

要刪除後立刻變色,在#7多加入下面3行
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 3 Then Call Worksheet_SelectionChange(Target)
End Sub

TOP

回復 14# av8d


不是的,跟模組無關,是你搞錯了
Public Sub,Private Sub不是拿來傳變數
samwang有幫你修正程式了,只是把一部份搬到模組

你#12的檔案,不用模組,改2行就正確了
第一行在 ComboBox1_Change()上面,加上
Public GBY
第二行刪掉Worksheet_SelectionChange重覆定義的gby
刪掉這個GBY As Variant

TOP

        靜思自在 : 道德是提昇自我的明燈,不該是呵斥別人的鞭子。
返回列表 上一主題