ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

½Ð±Ð­n¦p¦ó´M§ä¨Ã±Æ§Ç~

½Ð±Ð­n¦p¦ó´M§ä¨Ã±Æ§Ç~

ªí ¤@ .
1 ­^¤å 25
1 °ê¤å 85
2 ­^¤å 80
2 °ê¤å 53
2 ¾ú¥v 88
3 °ê¤å 33
3 ¦a²z 55
4 ­^¤å 66
4 °ê¤å 22
4 ¦a²z 55

§Æ±æ¯à°µ¥X·í§Ú¦bªí¤Gªºa1¿é¤H½s¸¹«áa2¥i¥H¦Û°Ê¦C¥X¤U­±ªº§C¨ì°ªªº±Æ§Ç¡A¦p

·ía1½ü¤J "2" ®É.

°ê¤å 53
­^¤å 80
¾ú¥v 88

¿é¤J"3"®É..

°ê¤å 33
¦a²z 55

----------
¦³°ª¤â¥i¥HÀ°À°¦£¶Ü~

¥»©«³Ì«á¥Ñ yen956 ©ó 2014-3-23 05:40 ½s¿è

¸Õ¸Õ¬Ý:
  1. 'Sheet1 ªºVBA
  2. '¸ê®Æ¾ã²z
  3. Private Sub CommandButton1_Click()
  4.     Dim sh1, sh2 As Worksheet, rngA As Range
  5.     Dim endRow As Integer
  6.     Set sh1 = Sheets(1): Set sh2 = Sheets(2)
  7.    
  8.     endRow = sh1.[A1].End(xlDown).Row
  9.     sh2.[B1].Resize(endRow, 2) = ""
  10.    
  11.     '±N sh1.ÄæA «ö¤É¾­±Æ§Ç
  12.     sh1.[A1].Resize(endRow, 3).Sort _
  13.               Key1:=sh1.[A1], Order1:=xlAscending, _
  14.               Key2:=sh1.[C1], Order2:=xlAscending, _
  15.               Header:=xlYes
  16.    
  17.     '­«·s©w¸q¦WºÙ "x" ªº½d³ò(sh1.ÄæA)
  18.     ActiveWorkbook.Names("x").Delete
  19.     ActiveWorkbook.Names.Add Name:="x", RefersToR1C1:="=Sheet1!R1C1:R" & endRow & "17C1"   
  20. End Sub
  21.    
  22. 'Sheet2 ªºVBA
  23. '±ý¦bsh2.ÄæA ¸ê®ÆÅܧó®ÉIJµo¨Æ¥ó, ¥i¥Î Intersect ¤èªk§¹¦¨¡G
  24. Private Sub Worksheet_Change(ByVal Target As Range)
  25.     Dim sh1, sh2 As Worksheet, rngA As Range
  26.     Dim endRow, cnt As Integer
  27.     Set sh1 = Sheets(1): Set sh2 = Sheets(2)
  28.    
  29.     '±N¤½¦¡ MATCH ¿é¤J sh2.[F1]
  30.     '±N sh2.ÄæA ©Ò¿é¤Jªº ½s¸¹, ¥Î¤½¦¡ MATCH Àò¨ú ¹ïÀ³¨ì sh1.ÄæA ªº°_©l¦C¸¹
  31.     sh2.[F1] = "=MATCH(E1, x, 0)"
  32.    
  33.     endRow = sh1.[A1].End(xlDown).Row
  34.    
  35.     '­­©w ¸ê®ÆÅܧó®ÉIJµo¨Æ¥ó ªº¦³®Ä½d³ò¦b rngA ¤º
  36.     Set rngA = sh2.[A1].Resize(endRow, 1)
  37.    
  38.     If Not Intersect(Target, rngA) Is Nothing Then
  39.    
  40.         '±N­è­èÅÜ§óªº Target, ¦s¤J sh2.[E1], ¨Ñ sh2.[F1] ªº¤½¦¡ MATCH ¤ñ¹ï¥Î
  41.         sh2.[E1] = Target
  42.         
  43.         '­Y sh2.[F1] ¬O¼Æ­È, ªí¥Ü­è­è¿é¤J¤F ¦³®Ä¼Æ¦r
  44.         If Application.IsNumber(sh2.[F1]) Then
  45.             cnt = 0
  46.             Do
  47.                 Target.Offset(cnt, 1) = sh1.Cells(cnt + sh2.[F1], 2)
  48.                 Target.Offset(cnt, 2) = sh1.Cells(cnt + sh2.[F1], 3)
  49.                 cnt = cnt + 1
  50.             Loop Until sh1.Cells(cnt + sh2.[F1], 1) > sh1.Cells(sh2.[F1], 1) Or sh1.Cells(cnt + sh2.[F1], 1) = ""
  51.         End If
  52.     End If
  53. End Sub
½Æ»s¥N½X

TOP

        ÀR«ä¦Û¦b : ¯àµ½¥Î®É¶¡ªº¤H¡A¥²¯à´x´¤¦Û¤v§V¤Oªº¤è¦V¡C
ªð¦^¦Cªí ¤W¤@¥DÃD