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

[µo°Ý] Excel VBA sorting «á½Æ»s¶K¤W

¦^´_ 1# tommy.lin
  1. Sub ex()
  2. With Sheets("Sheet1")
  3. If Application.CountA(.[B:B]) = 0 Then Exit Sub
  4.    For Each a In .Range("B:B").SpecialCells(xlCellTypeConstants)
  5.       With Sheets("Data")
  6.       Set c = .Rows(1).Find(a, lookat:=xlWhole)
  7.       k = IIf(Sheets("result").Cells(1, .Columns.Count).End(xlToLeft) = "", 0, 1)
  8.       Range(c, c.End(xlDown)).Copy Sheets("result").Cells(1, .Columns.Count).End(xlToLeft).Offset(, k)
  9.       End With
  10.    Next
  11. End With
  12. End Sub
½Æ»s¥N½X
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

¦^´_ 4# tommy.lin
¤£À´ªº¦a¤è«öF1¬Ý»¡©ú¬O³Ì¦nªº®ÑÄy   
Sub ex()
With Sheets("Sheet1")
If Application.CountA(.[B:B]) = 0 Then Exit Sub  'BÄæµL¸ê®Æ´N¸õ¥Xµ{§Ç
   For Each a In .Range("B:B").SpecialCells(xlCellTypeConstants)  '´`Àô¨C­ÓBÄæªº¸ê®Æ
      With Sheets("Data")
      Set c = .Rows(1).Find(a, lookat:=xlWhole)  '¦bSheets("Data")²Ä¤@¦C§ä´M
      k = IIf(Sheets("result").Cells(1, .Columns.Count).End(xlToLeft) = "", 0, 1)  '°²¦p­n½Æ»sªº¥Ø¼Ð¦ì¸m¦bSheets("result")ªºAÄæ¡A¦ì²¾¶q¬°0
      Range(c, c.End(xlDown)).Copy Sheets("result").Cells(1, .Columns.Count).End(xlToLeft).Offset(, k) '½Æ»s¸ê®Æ
      End With
   Next
End With
End Sub
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

        ÀR«ä¦Û¦b : ¡i¥Í©R¦b©I§l¶¡¡j¦òªû»¡¡G¡u¥Í©R¦b©I§l¶¡¡C¡v¤HµLªkºÞ¦í¦Û¤vªº¥Í©R¡A§óµLªk¾×¦í¦º´Á¡AÅý¦Û¤v¥Ã¦í¤H¶¡¡C¬JµM¥Í©R¥h¨Ó³o»òµL±`¡A§Ú­Ì§óÀ³¸Ó¦n¦n¦a·R±¤¥¦¡B§Q¥Î¥¦¡B¥R¹ê¥¦¡AÅý³oµL±`¡BÄ_¶Qªº¥Í©R¡A´²µo¥¦¯uµ½¬üªº¥ú½÷¡A¬M·Ó¥X¥Í©R¯u¥¿ªº»ù­È¡C
ªð¦^¦Cªí ¤W¤@¥DÃD