Skip to content

Commit 8f0470b

Browse files
authored
Merge pull request #1869 from a-sadegh63/patch-1
Update Excel.Worksheet.BeforeDoubleClick.md
2 parents ea996a4 + afc4585 commit 8f0470b

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

api/Excel.Worksheet.BeforeDoubleClick.md

+22-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,27 @@ The **[DoubleClick](Excel.Application.DoubleClick.md)** method doesn't cause thi
3636

3737
This event doesn't occur when the user double-clicks the border of a cell.
3838

39-
40-
39+
## Example
40+
This example changes the fill color of cells around the target cell when the worksheet cell is double-clicked.
41+
```
42+
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
43+
Dim targetCol As Integer, StartCol As Integer
44+
Dim targetRow As Integer, StartRow As Integer
45+
Me.Cells.ClearFormats
46+
targetRow = Target.Row
47+
targetCol = Target.Column
48+
If targetRow - 1 >= 1 Then
49+
StartRow = targetRow - 1
50+
Else
51+
StartRow = targetRow
52+
End If
53+
If targetCol - 1 >= 1 Then
54+
StartCol = targetCol - 1
55+
Else
56+
StartCol = targetCol
57+
End If
58+
Me.Range(Me.Cells(StartRow, StartCol), Me.Cells(targetRow + 1, targetCol + 1)).Interior.Color = vbYellow
59+
End Sub
60+
```
4161

4262
[!include[Support and feedback](~/includes/feedback-boilerplate.md)]

0 commit comments

Comments
 (0)