- ©«¤l
- 1446
- ¥DÃD
- 40
- ºëµØ
- 0
- ¿n¤À
- 1470
- ÂI¦W
- 0
- §@·~¨t²Î
- Windows 7
- ³nÅ骩¥»
- Excel 2010 & 2016
- ¾\ŪÅv
- 50
- ©Ê§O
- ¨k
- ¨Ó¦Û
- ¥xÆW
- µù¥U®É¶¡
- 2020-7-15
- ³Ì«áµn¿ý
- 2024-11-28
|
¦^´_ 9# jsc0518
ÁÂÁ«e½ú¦^´_
¤µ¤Ñ½Æ²ß¦AÀˬd¤F¤@¤U¨Ã§@µù¸Ñ,½Ð«e½ú°Ñ¦Ò
Option Explicit
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
With Target
'¡ô¥H¤U¬OÃö©ó¥ªÁäÂùÀ»ªºµ{§Ç
If .Count > 1 Then Exit Sub
'¡ô¦pªGIJµoªºÀx¦s®æ¼Æ¤j©ó1,´Nµ²§ôµ{¦¡°õ¦æ (¨Ò¦p:IJµoªº¬O¦X¨ÖÀx¦s®æ)
If InStr("/¥D/°Æ/¡´//", "/" & Trim(.Value) & "/") Then
'¡ô¦pªGIJµo®æÈ¥h°£«e«áªÅ¥Õ¦r¤¸«á,¦b«e«á³s±µ "/" ²Å¸¹ªº·s¦r¦ê,¥]§t¦b "/¥D/°Æ/¡´//"¦r¦ê¸Ì??
.Font.ColorIndex = 1
'¡ô¥OIJµo®æ¦r¦â¬O ¶Â¦â
.Value = Switch(.Value = "", "¡´", .Value = "¡´", "", .Value = "¥D", "", .Value = "°Æ", "")
'¡ô¥OIJµo®æȬO¥HSwitch ¨ç¦¡¦^¶Çªº¦r¦êÈ
'https://learn.microsoft.com/zh-tw/office/vba/language/reference/user-interface-help/switch-function
'¦pªGìÀx¦s®æȬO ªÅ¦r¤¸,´N¦^¶Ç "¡´"
'¦pªGìÀx¦s®æȬO "¡´",´N¦^¶Ç ªÅ¦r¤¸
'¦pªGìÀx¦s®æȬO "¥D",´N¦^¶Ç ªÅ¦r¤¸
'¦pªGìÀx¦s®æȬO "°Æ",´N¦^¶Ç ªÅ¦r¤¸
Cancel = True
'¡ô¨ú®ø¥ªÁäÂùÀ»ªºì¥\¯à
End If
End With
End Sub
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
With Target
'¡ô¥H¤U¬OÃö©ó¥kÁä³æÀ»ªºµ{§Ç
If .Count > 1 Then .Font.ColorIndex = 1: Call ÀË´ú_¿ï¨ú°ÝÃD®æ: Exit Sub
'¡ô¦pªGIJµoªºÀx¦s®æ¼Æ¤j©ó1,¥OIJµo®æ¦r¦â¬O ¶Â¦â,°õ¦æ (ÀË´ú_¿ï¨ú°ÝÃD®æ)°Æµ{¦¡,µ²§ôµ{¦¡°õ¦æ
If InStr("/¥D/°Æ/¡´//", "/" & Trim(.Value) & "/") Then
'¡ô¦pªGIJµo®æÈ¥h°£«e«áªÅ¥Õ¦r¤¸«á,¦b«e«á³s±µ "/" ²Å¸¹ªº·s¦r¦ê,¥]§t¦b "/¥D/°Æ/¡´//"¦r¦ê¸Ì??
.Value = Switch(.Value = "", "¥D", .Value = "¡´", "¥D", .Value = "¥D", "°Æ", .Value = "°Æ", "¥D")
'¡ô¥OIJµo®æȬO¥HSwitch ¨ç¦¡¦^¶Çªº¦r¦êÈ
'¦pªGìÀx¦s®æȬO ªÅ¦r¤¸,´N¦^¶Ç "¥D"
'¦pªGìÀx¦s®æȬO "¡´",´N¦^¶Ç "¥D"
'¦pªGìÀx¦s®æȬO "¥D",´N¦^¶Ç "°Æ"
'¦pªGìÀx¦s®æȬO "°Æ",´N¦^¶Ç "¥D"
Cancel = True
'¡ô¨ú®ø¥kÁä³æÀ»ªºì¥\¯à
End If
End With
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
With Target
'¡ô¥H¤U¬OÃö©óÀx¦s®æ¤º®e½s¿èIJµoªºµ{§Ç
Call ÀË´ú_¿ï¨ú°ÝÃD®æ
'¡ô°õ¦æ (ÀË´ú_¿ï¨ú°ÝÃD®æ)°Æµ{¦¡
End With
End Sub
Option Explicit
Sub ÀË´ú_¿ï¨ú°ÝÃD®æ()
Dim Arr, xR As Range, C%, i&, R&, n&
'¡ô«Å§iÅܼÆ! (Arr)¬O³q¥Î«¬ÅܼÆ,(xR)¬OÀx¦s®æÅܼÆ,(C)¬Oµu¾ã¼ÆÅܼÆ,(i,R,n)¬Oªø¾ã¼ÆÅܼÆ
Arr = ActiveSheet.UsedRange
'¡ô¥OArr³o³q¥Î«¬ÅܼƬO¤Gºû°}¦C,¥H²{ªí¦³¨Ï¥ÎÀx¦s®æÂX®i³Ì¤p¤è¥¿½d³òÀx¦s®æÈˤJ
For C = 1 To UBound(Arr, 2)
'¡ô³]¶¶°j°é!C±q1¨ìArr°}¦C¾î¦V³Ì¤j¯Á¤ÞÄ渹¼Æ
For R = 1 To UBound(Arr)
'¡ô³]¶¶°j°é!R±q1¨ìArr°}¦CÁa¦V³Ì¤j¯Á¤Þ¦C¸¹¼Æ
If InStr("/¥D/°Æ/¡´/", "/" & Trim(Arr(R, C)) & "/") Then
'¡ô¦pªG°j°éArr°}¦CÈ¥h°£«e«áªÅ¥Õ¦r¤¸«á,¦b«e«á³s±µ "/" ²Å¸¹ªº·s¦r¦ê,¥]§t¦b ""/¥D/°Æ/¡´/""¦r¦ê¸Ì??
If Cells(R, C).Font.ColorIndex <> 1 Then Cells(R, C).Font.ColorIndex = 1
'¡ô¦pªG°j°éÀx¦s®æ¦r¦â¤£¬O¶Â¦â!´NÅܬ° ¶Â¦â
n = n + 1
'¡ô¥On³oªø¾ã¼ÆÅܼƲ֥[ 1
If n >= 7 Then
'¡ô¦pªGnÅÜ¼Æ > 7 ??
If Not xR Is Nothing Then
'¡ô¦pªGxR³oÀx¦s®æÅܼƤw¦³ª«¥ó
Set xR = Union(xR, Cells(R, C))
'¡ô¥OxRÅܼƱN °j°éÀx¦s®æ¯Ç¤J¦b xRÅܼƫá±,¦¨¬°·sªºÀx¦s®æ¶°
Else
Set xR = Cells(R, C)
'¡ô§_«h¥OxR ¬O°j°éÀx¦s®æ
End If
End If
Else
n = 0
'¡ô¥OnÅܼÆÂk¹s
End If
Next
n = 0
'¡ô¥OnÅܼÆÂk¹s(¦]¬°¸óÄ椣¦A²Ö¥[¤W¯Z¤Ñ¼Æ)
Next
If Not xR Is Nothing Then
'¡ô¦pªGxR³oÀx¦s®æÅܼƤw¦³ª«¥ó
Application.Goto xR
'¡ô¿ï¨úxRÅܼÆÀx¦s®æ
xR.Font.ColorIndex = 3
'¡ô¥OxRÅܼÆÀx¦s®æ¦r¦â¬O ¬õ¦â
MsgBox "**** ³sÄò¤C¤Ñ¤W¯Z! ****"
'¡ô¸õ¥X´£¥Üµ¡
End If
End Sub |
|