返回列表 上一主題 發帖

[發問] 如何轉置並重組資料排列方式

回復 3# luke
  1. Option Explicit
  2. Sub Ex()
  3.     Dim Ar(2 To 3), E As Range
  4.     With sheet1
  5.         Ar(2) = .Columns(2)                       'B欄資料 置入陣列
  6.         Ar(3) = .Columns(3)                       'C欄資料 置入陣列
  7.         .Columns(2) = Ar(3)                       'B欄資料轉成C欄資料
  8.         .Columns(3) = Ar(2)                       'C欄資料轉成B欄資料
  9.         .Columns(2).Replace "*運送組", ""         'B欄資料 消除字串 *運送組
  10.         .Columns(2).Replace "*停車亭", ""         'B欄資料 消除字串 *停車亭
  11.         .Columns(2).Replace "*休息", ""           'B欄資料 消除字串 *休息
  12.         .Range("E:I").Clear
  13.         For Each E In .Range("A:C").SpecialCells(xlCellTypeConstants).Areas
  14.         'Areas 屬性 傳回 Areas 集合,此集合代表多重範圍中的所有範圍。唯讀。
  15.            E.Copy                                                 '複製
  16.             With .Range("E" & .Rows.Count).End(xlUp).Offset(1)    'E欄由下往上
  17.                 .PasteSpecial , Transpose:=True                   '轉置
  18.                 If .Cells(1, 3) = "站牌終點" Then .Cells(1, 3).Resize(3).Cut Destination:=.Cells(1, 5)
  19.                  .Resize(3, 5).Borders.LineStyle = xlNone           '消除框線
  20.                 .Resize(3, 5).BorderAround 1                        '製定外框線
  21.             End With
  22.         Next
  23.          .Range("E:I").EntireColumn.AutoFit
  24.          .Range("E1").Select
  25.         .Columns(2) = Ar(2)                                              '還原B欄資料                       
  26.         .Columns(3) = Ar(3)                                              '還原C欄資料                       
  27.     End With
  28. End Sub
複製代碼

TOP

        靜思自在 : 有多少力量就做多少事,不要心存等待,等待才會落空。
返回列表 上一主題