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

[µo°Ý] Excel VBA¦³¤°»ò²{¦³ªº¨ç¼Æ¥i¥H¥Î¨Ó§ä´M¤Gºû°}¦C¤¤ªº¸ê®Æ¡H

[µo°Ý] Excel VBA¦³¤°»ò²{¦³ªº¨ç¼Æ¥i¥H¥Î¨Ó§ä´M¤Gºû°}¦C¤¤ªº¸ê®Æ¡H

¦U¦ì«e½ú¦n¡A§Ú­è¥ÎExcel  VBA¼g¥¨¶°¨S¦h¤[¡A¥Ø«e§Ú·|±N¤u§@ªí¤¤ªº¸ê®Æ¡A¥ýŪ¨ì°}¦C«á¦A°µ¹Bºâ(³o¼Ë°õ¦æ³t«×¸û§Ö)

¥­±`¬d¬Y­Ó­È¦³¨S¦³¦b°}¦C¤¤«Ü¦n¤ñ¹ï¡A¦ý³Ìªñ¹J¨ì¤@­Óª¬ªp¡A´N¬O§Ú­n¬dA­È(¨Ò¦p¨­¥÷ÃÒ¸¹)¦³¨S¦³¦bB°}¦C¤¤¡A¦ýB°}¦C¤¤¡A¨C­Ó¦æ¦C­È¡A¨Ã¤£³æ¯Â¬O¨­¥÷ÃÒ¸¹¡A¦Ó¥B¤@ªø¦êªº¤å¦r(¥i¯à¦³¤Q´X­Ó¦r¡A¦Ó¨ä¤¤¥]§t¤F¨­¥÷ÃÒ¸¹)¡A

¦³¤°»ò²{¦³ªº¨ç¼Æ©Î¤èªk¥i¥H¥Î¨Ó¤ñ¹ïA­È¦³¨S¦³¦bB°}¦C¤¤¡H  ~~·s¤â´£°Ý¡A·Ð½Ð¤j®a«ü±Ð~~ÁÂÁÂ~~
¥V¥V

³oExcelÀɸ̦³3­Ó¤u§@ªí¡A¤u§@ªí¤¤ªºÃÄ¥NÄæ¬O¥D­n¸ê®Æ¡A§Ú­n±qÃħ÷Àɪº¸ê®Æ¤¤¡A¤ñ¹ïÃÄ¥N¬O§_¤@¼Ë¡A¥Ø«e¤w¸g¥i¥H¤ñ¹ïÃÄ¥N¡B°·«O½X¡BÃĦW¬O§_¬Û¦P¡F¦ýÃħ÷Àɤ¤ªº"DK"¦C¡A¦³³oÃÄ«~ªº¾ú¥v­×§ï¸ê®Æ¡A§Ú·Q¥Î°·«O½X¸òDK¦C¤ñ¹ï¡A¬ÝDK¦C¤¤¬O§_¦³¬Û¦Pªº°·«O½X¡A¤£ª¾¹D¦³¤°»ò¤èªk¥i¥H¨Ï¥Î¡H

°w¾¯Âå¥O¥N½X¤ñ¹ï-test.zip (38.57 KB)

¥V¥V

TOP

¥»©«³Ì«á¥Ñ GBKEE ©ó 2018-6-11 14:09 ½s¿è

¦^´_ 2# newstarmoon
¸Õ¸Õ¬Ý
  1. Option Explicit
  2. Sub Ex()
  3.     Dim AR(), Ar1(), Ar2(), i As Long, ii As Long, iii As Long, Msg As String
  4.     Dim xRow As Integer
  5.     Ar1 = Array("a", "b", "d") '§AªºCÄæÁôÂäF
  6.     ReDim AR(1 To UBound(Ar1) + 1)
  7.     Sheets("¹Bºâ").UsedRange.Clear
  8.     With Sheets("¤u§@ªí")
  9.         For i = 1 To UBound(Ar1) + 1
  10.             ii = IIf(.Cells(Rows.Count, Ar1(i - 1)).End(xlUp).Row > ii, .Cells(Rows.Count, Ar1(i - 1)).End(xlUp).Row, ii)
  11.             '¦pªG¬Y¤@¦Cªº¸ê®Æ¦³100¦æ¡A¦Ó²Ä5¦æ¬OªÅ¥Õ
  12.             '***¥²¶·§ä¥X©Ò¦³Äæ¦ì¤¤³Ì«á¸ê®Æ¦³ªº¦C¸¹ ***
  13.         Next
  14.         For i = 1 To UBound(Ar1) + 1
  15.             AR(i) = Application.WorksheetFunction.Transpose(.Range(Ar1(i - 1) & "1").Resize(ii).Value)
  16.         Next
  17.     End With
  18.     With Sheets("Ãħ÷ÀÉ")
  19.         Ar1 = .Range(.[A5], .[A5].End(xlDown)).Resize(, 5).Value
  20.         For i = 1 To .[A5].End(xlDown).Row - 4
  21.             Ar1(i, 5) = .Range("DK" & i + 4) '**¥[¤J"DK"Äæ
  22.         Next
  23.     End With
  24.     For i = 2 To UBound(AR(1)) 'ÃÄ¥N
  25.         '**************************
  26.         '"¤u§@ªí"
  27.         'AR(1)(i)=>ÃÄ¥N    AR(2)(i)=>Ãijæ¦W    AR(3)(i)=>°·«O½X
  28.         '**************************
  29.         '"Ãħ÷ÀÉ"
  30.         'Ar1(ii, 1)=>ÃÄ¥N    Ar1(ii, 2)=>¥N¸¹    Ar1(ii, 3)=>°·«O½X  Ar1(ii, 4)=>ÃĦW
  31.         'Ar1(ii, 5)=>DK
  32.         '**************************
  33.         
  34.         Msg = ""
  35.         For ii = 1 To UBound(Ar1)
  36.             If AR(1)(i) <> "" And Ar1(ii, 1) <> AR(1)(i) Then    'ÃÄ¥N¤£¬Û¦P
  37.                 'InStr(Ar1(ii, 5), (AR(3)(i))) ->¬d¬Ý¦³µL¬Û¦P°·«O½X
  38.                 If UCase(Ar1(ii, 4)) = UCase(AR(2)(i)) Or UCase(Ar1(ii, 3)) = UCase(AR(3)(i)) Or InStr(Ar1(ii, 5), (AR(3)(i))) Then
  39.                     Msg = Msg & IIf(Msg <> "", ",", "") & ii  '¤ñ¹ï¨ì±a¤J
  40.                 End If
  41.             End If
  42.         Next
  43.         If Msg <> "" Then
  44.             With Sheets("¹Bºâ").Cells(Rows.Count, "A").End(xlUp)
  45.               xRow = IIf(.Row = 1, 0, 2)
  46.                 Ar2 = Application.Index(Application.WorksheetFunction.Transpose(AR), 1)
  47.                 .Offset(xRow).Resize(, UBound(Ar2)) = Ar2
  48.                 Ar2 = Application.Index(Application.WorksheetFunction.Transpose(AR), i)
  49.                 .Offset(xRow + 1).Resize(, UBound(Ar2)) = Ar2
  50.                 Ar2 = Array("ÃÄ¥N", "¥N¸¹", "°·«O½X", "ÃĦW", "DKÄæ")
  51.                 .Offset(xRow + 2).Resize(, UBound(Ar2) + 1) = Ar2
  52.             End With
  53.             With Sheets("¹Bºâ").Cells(Rows.Count, "A").End(xlUp).Offset(1)
  54.                For iii = 0 To UBound(Split(Msg, ","))
  55.                 Ar2 = Application.Index(Ar1, Split(Msg, ",")(iii))
  56.                .Offset(iii).Resize(, UBound(Ar2)) = Ar2
  57.                Next
  58.             End With
  59.         End If
  60.     Next
  61. End Sub
½Æ»s¥N½X
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

ÁÂÁª©¥Dªº¦^´_¡A¦]¬°§Ú¥u¦³¤»¤é¤ñ¸û¦³ªÅ¡A©Ò¥H³o¤@¨â¤Ñ¤~ªá®É¶¡¦n¦n²z¸Ñª©¥Dªºµ{¦¡½X¡F
¥J²Ó¬ã¨s§¹«á¡Aª©¥Dªºµ{¦¡½XÅý§Ú¨ü¯q¨}¦h¡A¤]¾Ç¨ì¤F³\¦h·§©À¡C
¹³§A¥Îªº"InStr"¨ç¼Æ¡A´N¬O§Ú´£°Ý¤¤¡A³Ì»Ý­nªº¨ç¼Æ¡A§Ú·|¦n¦n¹B¥Î¥¦¡F§A¥t¥~¦³¥Î¤F"Split"¨ç¼Æ¡A§Ú¦³¥h¬d¤FSplit¨ç¼Æªº¥Îªk¡A³o¨ç¼Æ¥\¯à¯uªº«Ü¤£¿ù¡A§Ú·|¥J²Ó°O¤U¨Ó¡C

¥t¥~¦A½Ð±Ðª©¥D¤@­Ó°ÝÃD¡A§Aµ{¦¡½X¤¤"AR(i) = Application.WorksheetFunction.Transpose(.Range(Ar1(i - 1) & ":" & Ar1(i - 1)).SpecialCells(xlCellTypeConstants).Value)"³o¤@¬q¡A¦pªG¬Y¤@¦Cªº¸ê®Æ¦³100¦æ¡A¦Ó²Ä5¦æ¬OªÅ¥Õ¡A«á­±±µµÛ¦³¸ê®Æ¡A¦ý³o¤@¬qµ{¦¡¡A¥¦Åª¨ì²Ä5¦æ¬OªÅ¥Õ«á´Nµ²§ô¤£·|¦AŪ¤U¥h¡A³o¦³¨S¦³¤°»ò¤èªk¥i¥H§ï¨}¡H

ÁÂÁª©¥Dªº²Ó¤ß¦^ÂÐ~~
¥V¥V

TOP

ª©¥D§A¦n¡A§Ú³Ìªñ¦³¸I¨ì¤@­Ó¤p°ÝÃD­n¦A½Ð±Ð§A¤@¤U

For i = 1 To UBound(Ar1) + 1
            AR(i) = Application.WorksheetFunction.Transpose(.Range(Ar1(i - 1) & "1").Resize(ii).Value)

¤W­±³o¬qµ{¦¡½X¡A¥­±`¦b¥Îªº®É­Ô³£ok¡A¦ý§Ú³Ìªñ¹J¨ì§Úªº¸ê®Æ¦æ¼Æ¶W¹L6¸U¦h¦æ®É¡A³o¤@¬qµ{¦¡½X´N·|¥X¿ù¡A¤£ª¾¹D¬O¤£¬OTranspose¦³¤°»ò­­¨î¡A©ÎªÌ¦³¤°»ò¤èªk¥i¥H§ïµ½¡H

ÁÂÁª©¥D~~
¥V¥V

TOP

        ÀR«ä¦Û¦b : ¤@­Ó¯Ê¤fªºªM¤l¡A¦pªG´«¤@­Ó¨¤«×¬Ý¥¦¡A¥¦¤´µM¬O¶êªº¡C
ªð¦^¦Cªí ¤W¤@¥DÃD