|
修改了一下,看看行不行
- Dim oDpd As Object
- Dim sFml1 As String
- Dim prvTarget As Range
- Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
- Const dFixedPos As Double = 0.8
- Const dFixWidth As Double = 10 'Change here to change Width of the DropDown
- Const ValidWidth = 2 '宽度倍数
- Dim vld As Validation
- Dim lDpdLine As Long
- Dim str As String
- On Error GoTo 0
- Set vld = Target.Validation
- On Error GoTo Terminate
- sFml1 = "vld.Formula1" '这里随便加入一个字符串
- On Error GoTo 0
- Set prvTarget = Target
- 'lDpdLine = Range(Mid(sFml1, 2)).Item(oDpd.Value)
- lDpdLine = Cells(Rows.Count, 1).End(xlUp).Row
- With Target
- Set oDpd = ActiveSheet.DropDowns.Add( _
- .Left - dFixedPos, _
- .Top - dFixedPos, _
- .Width + dFixWidth + dFixedPos * 2, _
- .Height + dFixedPos * 2)
-
- End With
- If Target.Count > 1 Then
- Set oDpd = Nothing
- Exit Sub
- End If
- With oDpd
- .ListFillRange = sFml1
- .DropDownLines = lDpdLine
- .Display3DShading = True
- .Text = Target.Value
- End With
- If Not prvTarget Is Nothing Then
- If Not oDpd Is Nothing Then
- If oDpd.Value = 0 Then
- prvTarget.Value = prvTarget.Value
- ' prvTarget.Value = vbNullString
- Else
- prvTarget.Value = Range(Mid(sFml1, 2)).Item(oDpd.Value)
- End If
- Set prvTarget = Nothing
- End If
- Else
-
- End If
- On Error Resume Next
- oDpd.Delete
- sFml1 = vbNullString
- Set oDpd = Nothing
- Terminate:
- 'Cells.FormatConditions.Delete '行列十字交叉高亮显示
- ' With Target.EntireColumn '行列十字交叉高亮显示
- ' .FormatConditions.Add xlExpression, , "=true" '行列十字交叉高亮显示
- ' .FormatConditions(1).Interior.ColorIndex = 36 '行列十字交叉高亮显示
- ' End With '行列十字交叉高亮显示
- ' With Target.EntireRow '行列十字交叉高亮显示
- ' .FormatConditions.Add xlExpression, , "=true" '行列十字交叉高亮显示
- '.FormatConditions(2).Interior.ColorIndex = 36 '行列十字交叉高亮显示
- ' End With '行列十字交叉高亮显示
-
- End Sub
复制代码 |
|