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

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

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

·Q½Ð°ÝªO¤W°ª¤â
¦pªþ¥ó
§Ú¦³¨â­Ó¤U©Ô¿ï³æªºÄæ¦ì¤º®e¤À§O¬° ABCDEF
ABCDEF ¬°§Úªº¸ê®Æ­¶­±DataªºªíÀY.
¦pªG§Úªº¤U©Ô¿ï³æ²Ä¤@­Ó¿ï¤FB ²Ä¤G­Ó¿ï¤FA
µM«á°õ¦æVB «áVB ·|¥ý¦b Data ­¶­±§ä¨ìB µM«á±NBÄæ¾ãÄæ½Æ»s¨ìResult­¶­±ªºAÄæ¦ì¥h,¦b°µ²Ä¤G¦¸§ä¨ìA µM«áA ½Æ»s¨ìResult­¶­±ªºBÄæ¦ì¥h
¤£ª¾¹DVB ªºµ{¦¡À³¸Ó«ç»ò¼g....·PÁªO¤W°ª¤â


Regards
:)

Book1.rar (6.75 KB)

¦^´_ 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

½Ð±Ðª©¥D¦³±ÀÂ˪º®Ñ? ¥i¥H¬d¨ì¦³Ãöª©¥Dªºcode

TOP

·PÁª©¥D....¤£¹Lµ{¦¡¤Óºë²@@ §¹¥þ¤£ÁA¸Ñ­Ó¨BÆJ°µ¤F¬Æ»ò....

TOP

¦^´_ 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

        ÀR«ä¦Û¦b : ¶¢¤HµL¼Ö½ì¡A¦£¤HµL¬O«D¡C
ªð¦^¦Cªí ¤W¤@¥DÃD