求助,Excel2003表格代码问题,非常感谢!

如题所述

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count = 1 And Target.Row = 9 Then
  Set x = Application.Intersect(Target, Range("B9:D9"))
     If Not (x Is Nothing) Then [Q9] = x.Column: [Q9].Font.Color = vbWhite
  Set y = Application.Intersect(Target, Range("F9:P9"))
    If Not (y Is Nothing) Then Cells(9, [Q9]) = Target
 End If
End Sub

温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-09-18
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim nr As Long, nc As Long
    Dim str As String
    nr = Target.Row
    nc = Target.Column
    If nr = 9 Then
    With Me
        If nc > 1 And nc < 5 Then
                'B-D列每次选择的单元格信息保存在工作表的最后一个单元格,你也可以改变
                .Cells(.Rows.Count, .Columns.Count) = Target.Address
        ElseIf nc > 5 And nc < 17 Then
            str = .Cells(.Rows.Count, .Columns.Count)
            If str <> "" Then
                .Range(str) = Target
            End If
        End If
    End With
    End If
End Sub


本回答被网友采纳