- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
5#
發表於 2012-11-19 16:47
| 只看該作者
回復 1# kai6929
不錯的分享,但同 一顧客選第二次時,在新增工作表的命名會錯誤
純參考;表單的程式碼- Private Sub myComboBox_Change()
- ' Call 製作請款書(myComboBox.Text)
- 製作請款書 '(myComboBox.Text)
- End Sub
- Private Sub UserForm_Initialize()
- 'myForm.myComboBox.List = Array("A公司", "B建設公司", "C電器公司", "D不動產公司") '
- '下列程式碼 可根據 "銷售資料" B欄的顧客 建立 myComboBox 的 List
- With Sheets("銷售資料")
- .Range("B3", .[B3].End(xlDown)).AdvancedFilter xlFilterCopy, , .Cells(1, Columns.Count), True
- 'AdvancedFilter 進階篩選 不重複的顧客名單到.Cells(1, Columns.Count)最後一欄
- With .Range(.Cells(2, Columns.Count), .Cells(2, Columns.Count).End(xlDown)) '第2列到最後有資料的列
- myComboBox.List = .Value
- .EntireColumn.Clear
- End With
- End With
- End Sub
- Private Sub 製作請款書()
- Application.ScreenUpdating = False
- With Sheets("銷售資料")
- .Range("A3").AutoFilter 2, myComboBox '自動篩選 B欄 myComboBox(顧客)
- .Columns(2).Hidden = True '隱藏B欄
- .Range("A3").CurrentRegion.Copy '複製篩選出的 日期,商品,單價,數量,金額
- .AutoFilterMode = False
- With Sheets("請款書雛形")
- .Range("A6") = myComboBox
- .Range("A11").CurrentRegion = "" '清除舊有資料
- .Range("A11").PasteSpecial xlPasteValuesAndNumberFormats '貼上 值及公式
- End With
- Application.CutCopyMode = False '取消複製的虛線
- .Columns(2).Hidden = False '取消隱藏B欄
- End With
- Application.ScreenUpdating = True
- End Sub
複製代碼 |
|