- ©«¤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
|
¥»©«³Ì«á¥Ñ yen956 ©ó 2014-3-23 05:40 ½s¿è
¸Õ¸Õ¬Ý:
- 'Sheet1 ªºVBA
- '¸ê®Æ¾ã²z
- Private Sub CommandButton1_Click()
- Dim sh1, sh2 As Worksheet, rngA As Range
- Dim endRow As Integer
- Set sh1 = Sheets(1): Set sh2 = Sheets(2)
-
- endRow = sh1.[A1].End(xlDown).Row
- sh2.[B1].Resize(endRow, 2) = ""
-
- '±N sh1.ÄæA «ö¤É¾±Æ§Ç
- sh1.[A1].Resize(endRow, 3).Sort _
- Key1:=sh1.[A1], Order1:=xlAscending, _
- Key2:=sh1.[C1], Order2:=xlAscending, _
- Header:=xlYes
-
- '«·s©w¸q¦WºÙ "x" ªº½d³ò(sh1.ÄæA)
- ActiveWorkbook.Names("x").Delete
- ActiveWorkbook.Names.Add Name:="x", RefersToR1C1:="=Sheet1!R1C1:R" & endRow & "17C1"
- End Sub
-
- 'Sheet2 ªºVBA
- '±ý¦bsh2.ÄæA ¸ê®ÆÅܧó®ÉIJµo¨Æ¥ó, ¥i¥Î Intersect ¤èªk§¹¦¨¡G
- Private Sub Worksheet_Change(ByVal Target As Range)
- Dim sh1, sh2 As Worksheet, rngA As Range
- Dim endRow, cnt As Integer
- Set sh1 = Sheets(1): Set sh2 = Sheets(2)
-
- '±N¤½¦¡ MATCH ¿é¤J sh2.[F1]
- '±N sh2.ÄæA ©Ò¿é¤Jªº ½s¸¹, ¥Î¤½¦¡ MATCH Àò¨ú ¹ïÀ³¨ì sh1.ÄæA ªº°_©l¦C¸¹
- sh2.[F1] = "=MATCH(E1, x, 0)"
-
- endRow = sh1.[A1].End(xlDown).Row
-
- '©w ¸ê®ÆÅܧó®ÉIJµo¨Æ¥ó ªº¦³®Ä½d³ò¦b rngA ¤º
- Set rngA = sh2.[A1].Resize(endRow, 1)
-
- If Not Intersect(Target, rngA) Is Nothing Then
-
- '±NèèÅÜ§óªº Target, ¦s¤J sh2.[E1], ¨Ñ sh2.[F1] ªº¤½¦¡ MATCH ¤ñ¹ï¥Î
- sh2.[E1] = Target
-
- 'Y sh2.[F1] ¬O¼ÆÈ, ªí¥Üèè¿é¤J¤F ¦³®Ä¼Æ¦r
- If Application.IsNumber(sh2.[F1]) Then
- cnt = 0
- Do
- Target.Offset(cnt, 1) = sh1.Cells(cnt + sh2.[F1], 2)
- Target.Offset(cnt, 2) = sh1.Cells(cnt + sh2.[F1], 3)
- cnt = cnt + 1
- Loop Until sh1.Cells(cnt + sh2.[F1], 1) > sh1.Cells(sh2.[F1], 1) Or sh1.Cells(cnt + sh2.[F1], 1) = ""
- End If
- End If
- End Sub
½Æ»s¥N½X |
|