- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
回復 3# luke - Option Explicit
- Sub Ex()
- Dim Ar(2 To 3), E As Range
- With sheet1
- Ar(2) = .Columns(2) 'B欄資料 置入陣列
- Ar(3) = .Columns(3) 'C欄資料 置入陣列
- .Columns(2) = Ar(3) 'B欄資料轉成C欄資料
- .Columns(3) = Ar(2) 'C欄資料轉成B欄資料
- .Columns(2).Replace "*運送組", "" 'B欄資料 消除字串 *運送組
- .Columns(2).Replace "*停車亭", "" 'B欄資料 消除字串 *停車亭
- .Columns(2).Replace "*休息", "" 'B欄資料 消除字串 *休息
- .Range("E:I").Clear
- For Each E In .Range("A:C").SpecialCells(xlCellTypeConstants).Areas
- 'Areas 屬性 傳回 Areas 集合,此集合代表多重範圍中的所有範圍。唯讀。
- E.Copy '複製
- With .Range("E" & .Rows.Count).End(xlUp).Offset(1) 'E欄由下往上
- .PasteSpecial , Transpose:=True '轉置
- If .Cells(1, 3) = "站牌終點" Then .Cells(1, 3).Resize(3).Cut Destination:=.Cells(1, 5)
- .Resize(3, 5).Borders.LineStyle = xlNone '消除框線
- .Resize(3, 5).BorderAround 1 '製定外框線
- End With
- Next
- .Range("E:I").EntireColumn.AutoFit
- .Range("E1").Select
- .Columns(2) = Ar(2) '還原B欄資料
- .Columns(3) = Ar(3) '還原C欄資料
- End With
- End Sub
複製代碼 |
|