- ©«¤l
- 522
- ¥DÃD
- 36
- ºëµØ
- 1
- ¿n¤À
- 603
- ÂI¦W
- 0
- §@·~¨t²Î
- win xp sp3
- ³nÅ骩¥»
- Office 2003
- ¾\ŪÅv
- 50
- ©Ê§O
- ¨k
- µù¥U®É¶¡
- 2012-12-13
- ³Ì«áµn¿ý
- 2021-7-11
|
¦^´_ 1# leiru
¤½¦¡§Ú¤£¤Ó·|,
VBA¸Õ¸Õ¬Ý:- Private Sub Worksheet_Change(ByVal Target As Range)
- Dim sh, sh2 As Worksheet
- Dim Rng As Range
- Dim i, lastRow As Integer
- Set sh = Sheets("³øªí¦C¦L")
- Set sh2 = Sheets("Á`ªí")
- Set Rng = sh.Range("B1:B2")
- If Not Intersect(Target, Rng) Is Nothing Then '©wIJ°Ê Worksheet_Change ªº½d³ò¬° sh.Range("B1:B2")
- If sh.[B1] = "" Then '¦pªG ¾P±b°_¤é¬OªÅ¥Õ,
- Exit Sub '«h¸õÂ÷
- ElseIf sh.[B2] <> "" And sh.[B2] < sh.[B1] Then '¦pªG ¾P±b°_¡B¨´¤é§¡¤£¬OªÅ¥Õ, ¦ý¾P±b°_¤é¤j©ó¾P±b¨´¤é,
- MsgBox "¾P±b°_¤éÀ³¤p©ó¾P±b¨´¤é" & Chr(10) & "½Ð¬d©ú¦A§@!!", vbCritical '«h¥Üĵ,
- Exit Sub '¦A¸õÂ÷
- End If
-
- sh.[C7].Resize(6, 4) = ""
- With sh2
- '¤U¦C10¦C, ¥u¦³¸ê®Æ¶Ã±¼®É, ¤~»Ý¦A°õ¦æ¤@¦¸
- '.[BG6] = "=MATCH(³øªí¦C¦L!B1,yy,0)" '¾P±b°_¤é ¦b"Á`ªí"ªº¦C¸¹
- '.[BG7] = "=MATCH(³øªí¦C¦L!B2,yy,0)" '¾P±b¨´¤é ¦b"Á`ªí"ªº¦C¸¹
- '.[BJ1] = "=SUM(BJ3:BJ368)" 'µ§¼Æ¥[Á`
- '.[BK1] = "=SUM(BK3:BK368)" 'µo²¼ª÷ÃB¥[Á`
- '.[BL1] = "=SUM(BL3:BL368)" '¤âÄò¶O¥[Á`
- '.[B2:E2].Copy .[BB2] '¶i¶¥¿z¿ï·Ç«h ªº¼ÐÃD
- '.[B2].Copy .[BG2]
- '.[BG3] = "<>" '¶i¶¥¿z¿ï·Ç«h¡÷¥h°£ ³øªí½s¸¹ ¬OªÅ¥ÕªºÀx¦s®æ
- 'sh.[E13].Resize(6, 4) = "=SUM(E7:E12)"
- 'sh.[F13].Resize(6, 4) = "=SUM(F7:F10,F12)"
-
- If sh.[B2] <> "" Then '¦pªG ¾P±b¨´¤é ¤£¬OªÅ¥Õ
- sh.[A3] = "=""¥xÆW¤À¤½¥q¡@¾P±b¤é¡G ""&TEXT($B1, ""yyyy/mm/dd"")&"" ~ ""&TEXT($B2, ""yyyy/mm/dd"")&"" «D°O¤í¥U³ø¼Æ"""
- .[BB3].Resize(400, 4) = ""
- For i = 0 To 5
- .[BI3].Resize(400, 4) = ""
- .Cells(.[BG6], 1).Offset(0, i * 4 + 1).Resize(.[BG7] - .[BG6] + 1, 4).Copy .[BB3] '±N±ý¿z¿ï½d³ò ½Æ»s¨ì¿z¿ïªí
- '¥h°£ªÅ¦C¤§¶i¶¥¿z¿ï
- .[BB2].Resize(.[BG7] - .[BG6] + 2, 4).AdvancedFilter Action:=xlFilterCopy, _
- CriteriaRange:=.Range("BG2:BG3"), CopyToRange:=.Range("BI2:BL2"), Unique:=True
- If .[BI3] = "" Then
- sh.Cells(i + 7, 3).Resize(1, 4) = "'-"
- Else
- lastRow = .[BI200].End(xlUp).Row
- sh.Cells(i + 7, 3).FormulaR1C1 = "=Á`ªí!R3C61 & ""~"" & Á`ªí!R" & lastRow & "C61" '³øªí½s¸¹
- sh.Cells(i + 7, 3).Copy
- sh.Cells(i + 7, 3).PasteSpecial Paste:=xlPasteValues '±N¤½¦¡ÂনÈ
- .[BJ1].Resize(1, 3).Copy
- sh.Cells(i + 7, 4).PasteSpecial Paste:=xlPasteValues '¶K¤W µ§¼Æ¥[Á`¡Bµo²¼¥[Á`¡B¤âÄò¶O¥[Á`
- End If
- Next
- Else '§_«h, ¾P±b¨´¤é ¬OªÅ¥Õ
- sh.[A3] = "=""¥xÆW¤À¤½¥q¡@¾P±b¤é¡G ""&TEXT($B1, ""yyyy/mm/dd"")&"" ~ «D°O¤í¥U³ø¼Æ"""
- For i = 0 To 5
- If .Cells(.[BG6], 1).Offset(0, i * 4 + 1) = "" Then
- sh.Cells(i + 7, 3).Resize(1, 4) = "'-"
- Else
- .Cells(.[BG6], 1).Offset(0, i * 4 + 1).Resize(1, 4).Copy
- sh.Cells(i + 7, 3).PasteSpecial Paste:=xlPasteValues
- End If
- Next
- End If
- End With
- sh.[B1].Select
- End If
- End Sub
½Æ»s¥N½X |
|