- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
回復 1# s13030029 - Option Explicit
- Sub Ex()
- Dim Rng(1 To 2) As Range, xRow As Integer, AR, i As Integer, xI As Integer
- With Sheets("工作表1")
- xRow = .[A9].End(xlDown).Row
- With .Range("$E$9:$G" & xRow)
- .AutoFilter
- .AutoFilter Field:=1, Criteria1:="=目視", Operator:=xlOr, Criteria2:="=游標卡尺"
- '***篩選後A欄到G欄的資料區域******
- Set Rng(1) = .Parent.Range("A10:G" & xRow).SpecialCells(xlCellTypeVisible)
- '*********************************
- Set Rng(2) = Sheets("工作表3").[A13]
- For i = 1 To Rng(1).Areas.Count '**篩選後資料 不一定是連續的
- For xI = 1 To Rng(1).Areas(i).Rows.Count ''**篩選後資料的 Areas 集合,此集合代表多區域選取範圍中的所有範圍。
- AR = Application.Transpose(Application.Transpose(Rng(1).Areas(i).Rows(xI)))
- 'Rng(1).Areas(i).Rows(xI) 轉換成一維陣列
-
- '***處理 篩選後A欄到G欄的資料區域 中有沒有資料的欄位******
- AR = Join(AR, ",") '陣列以","連結轉為文字
- Do While InStr(AR, ",,")
- AR = Replace(AR, ",,", ",") ' ** 消除多餘的"," '
- Loop
- AR = Split(Mid(AR, 1, Len(AR) - 1), ",") '文字以","轉為陣列
- With Rng(2)
- .Cells(1) = AR(0)
- .Cells(1, 2) = AR(1) & vbLf & AR(2)
- EX_格式 .Cells(1).Resize(5)
- EX_格式 .Cells(1, 2).Resize(5)
- End With
- Set Rng(2) = Rng(2).Offset(1)
- Next
- Next
- End With
- End With
- End Sub
- Sub EX_格式(ByVal Target As Range)
- With Target
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- .WrapText = False
- .Orientation = 0
- .AddIndent = False
- .IndentLevel = 0
- .ShrinkToFit = False
- .ReadingOrder = xlContext
- '.MergeCells = True
- .Merge
- End With
- End Sub
複製代碼 |
|