- ©«¤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
|
¥»©«³Ì«á¥Ñ Andy2483 ©ó 2022-12-19 08:52 ½s¿è
¦^´_ 24# ã´£³¡ªL
ÁÂÁ«e½ú«ü¾É
³o©«¾Ç¨ì«Ü¦hª¾ÃÑ,«á¾Ç¨S¦³¤Ñ¤~ªº¤Ñ¤À,¥u¯à¾a¶Ô¾Ç²ß¶Ô½m²ß
¾Ç²ßµ²ªG»P¤ß±oµù¸Ñ¦p¤U,½Ð¦P¾Ç¥iÂǦ¹©«¦A´£¥X¤£¦P¬Ýªk©ÎºÃ°Ý,
½Ð«e½ú̦A«ü¾É
¹Lµ{:
µ²ªG:
¤u§@ªí¼Ò²Õ:
Private Sub Worksheet_Change(ByVal Target As Range)
With Target
'¡ô¥H¤U¬OÃö©óIJµo(Àx¦s®æȽs¿è)«áªºµ{§Ç
If .Address <> "$E$5" Then Exit Sub
'¡ô¦pªGIJµo®æªº¦ì§}¤£¬O "$E$5",´Nµ²§ôµ{¦¡°õ¦æ
If IsDate(.Value) Then Call ¦X¨Ö¤ë¥÷
'https://learn.microsoft.com/zh-tw/office/vba/language/reference/user-interface-help/isdate-function
'IsDate()¦pªG¹Bºâ¦¡¬O¤é´Á©Î¬O¥i¿ëÃѬ°¦³®Äªº¤é´Á©Î®É¶¡¡A·|¶Ç¦^ True¡A§_«h·|¶Ç¦^ True ¡C§_«h¡A¥¦·|¶Ç¦^ False¡C
'ifªº±ø¥ó¦¨¥ß!´N°õ¦æ ¦X¨Ö¤ë¥÷ °Æµ{¦¡
'IJµo[E5]¥i¥H±a°_³sÂê¤ÏÀ³,¤½¦¡§ó·s,¤ë¥÷¤]§ó·s¤F
End With
End Sub
Module1:
Sub ¦X¨Ö¤ë¥÷()
Dim xR As Range, xA As Range, m$, m1$, m2$
'¡ô«Å§iÅܼÆ(xR,xA)¬OÀx¦s®æÅܼÆ,(m,m1,m2)¬O¦r¦êÅܼÆ
Application.ScreenUpdating = False
'¡ô¿Ã¹õµe±¼È¤£¸òµÛµ{§ÇÅܤưõ¦æµ²ªG
With Range("e4", Cells(5, Columns.Count).End(xlToLeft)(0))
'¡ô¥H¤U¬OÃö©óÀx¦s®æ[E4]¨ì²Ä5¦C³Ì¥kÃ䦳¤º®eÄæ¦ìÀx¦s®æªºµ{§Ç
.UnMerge: .ClearContents
'¡ô¨ú®ø¦X¨ÖÀx¦s®æ :²M°£Àx¦s®æ¤º®e
For Each xR In .Cells
'¡ô³]¶¶°j°é!¥OxR ¬O³o¨ÇÀx¦s®æ¤§¤@,±q«e±½ü¨ì«á±(¥ª¦Ü¥k)
m1 = Format(xR(2), "m")
'¡ô¥Om1¬O°j°éxR ¤U¤è1®æÀx¦s®æÅܤƬ°¦r¦ê(³W«h¬O:¨ú¤é´Áªº¤£¸É0¤ë¥÷)
'¦Pm1 = Format(xR.ITEM(2, 1), "m")
'https://learn.microsoft.com/zh-tw/office/vba/language/reference/user-interface-help/format-function-visual-basic-for-applications
m2 = Format(xR(2, 2), "m")
'¡ô¥Om2¬O°j°éxR ¤U¤è1¦C¥ª¤è1ÄæÀx¦s®æÅܤƬ°¦r¦ê(³W«h¬O:¨ú¤é´Áªº¤£¸É0¤ë¥÷)
'¦Pm2 = Format(xR.ITEM(2, 2), "m")
If m1 <> m Then
'¡ô¦pªGm1<>m ,m¦r¦êÅܼƪºªì©lȬO"",³o¼Ëªº§PÂ_¦¡¦b²Ä¤@®æ®É±ø¥ó´N·|¦¨¥ß!
'³o¬O«á¾Çn¾Ç²ßªº¤èªk!¬JµM³£ª¾¹Dn«Å§im¦r¦ê,¬°¤°»ò¤S¤£·|Åým¸òm1¤ñ´N·|±o¨ìµ²ªG!!
'»Ýn¸õ²æ¦r¦êÅܼƤ@©wnµ¹¤@Ó¦r¦ê¤~®³¨Ó°µÅÞ¿è§PÂ_ªº·Qªk!
'¶Ô¾Ç²ß¶Ô½m²ß¬Ý¬Ý¥i§_¸õ²æ,ÁÂÁ«e½ú«ü¾É
m = m1: Set xA = xR
'¡ôif±ø¥ó¦¨¥ß!´N¥Om=m1 ,¥OxAÀx¦s®æÅܼƬO xR
xR = Application.Text(xR(2), "[DBNum1]m¤ë")
'¡ô¥OxRÀx¦s®æÅܼÆȬO °j°éxR¤U¤è1®æÀx¦s®æÅܤƬ°¤p¼g¤ë¥÷¦r¦ê
'Text()·|¶Ç¦^«ü©w¤§ª«¥óªº®æ¦¡¤Æ¤å¦r¡C °ßŪªº String
'[DBNum1]:¤¤¤å¤p¼g
'[DBNum2]:¤¤¤å¤j¼g
End If
If m2 <> m Then Range(xR, xA).Merge
'¡ô¦pªGm2 <> m,´NÅýÀx¦s®æ(xR§À®æ, xAÀY®æ)¤§¶¡ªºÀx¦s®æ¦X¨Ö
Next
.Borders.LineStyle = 1
'¥O¾ãÓÀx¦s®æ¶°½d³ò®æ½u¬O²Ó¹ê½u
End With
End Sub
'¡ô¿Ã¹õµe±¦b°õ¦æµ²§ô«á¦Û°ÊÅã¥Ü³Ì«áµ²ªG |
|