- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
2#
發表於 2013-9-19 16:51
| 只看該作者
本帖最後由 GBKEE 於 2013-9-23 16:49 編輯
回復 1# s7659109
試試看- Sub Ex_特定值彙整到總表()
- Dim xNO As String, AR(), A, Sh As Worksheet, R As Range, i As Integer, xR As Integer
- xNO = InputBox("輸入貨號")
- If xNO = "" Then Exit Sub
- i = 1
- For Each Sh In Sheets
- If InStr(Sh.Name, "A0") = 1 Then
- For Each R In Sh.Range("a1").CurrentRegion.Columns("B").Cells
- If R.Text = xNO Then
- A = Sh.Range("a1").CurrentRegion.Rows(R.Row)
- ReDim Preserve AR(1 To i)
- AR(i) = A
- i = i + 1
- End If
- Next
- End If
- Next
- If i = 1 Then MsgBox "貨號: 找不到 " & xNO: Exit Sub
- With Sheets("總表").Range("A1").CurrentRegion
- .Parent.Activate
- .Offset(2).Clear
- .Range("A3").Resize(i - 1, UBound(A, 2)) = Application.Transpose(Application.Transpose(AR))
- xR = Sheets("總表").Range("A1").CurrentRegion.Rows.Count
- .Cells(3, 2).Resize(xR - 2).NumberFormatLocal = "@"
- .Cells(3, 2).Resize(xR - 2).FormulaR1C1 = xNO
- .Cells(xR + 1, 1) = "合計"
- .Cells(xR + 1, 5) = "=SUM(R[-1]C:R[-" & xR - 3 & "]C)"
- .Cells(xR + 1, 5) = .Cells(xR + 1, 5)
- .Cells(xR + 1, 8) = "=SUM(R[-1]C:R[-" & xR - 3 & "]C)"
- .Cells(xR + 1, 8) = .Cells(xR + 1, 8)
- .Cells(3, 2).Resize(xR - 2).NumberFormatLocal = "@"
- .Cells(3, 2).Resize(xR - 2).FormulaR1C1 = xNO
- 'Rows (xR + 1)
- .Rows(xR + 1).Interior.Color = vbYellow
- End With
- MsgBox "ok"
- End Sub
複製代碼 |
|