- 帖子
- 1018
- 主題
- 15
- 精華
- 0
- 積分
- 1058
- 點名
- 0
- 作業系統
- win7 32bit
- 軟體版本
- Office 2016 64-bit
- 閱讀權限
- 50
- 性別
- 男
- 來自
- 桃園
- 註冊時間
- 2012-5-9
- 最後登錄
- 2022-9-28
|
8#
發表於 2013-1-23 21:04
| 只看該作者
回復 7# billchenfantasy - Private Sub CommandButton1_Click()
- Dim Source, f
- Dim rng As Range
- '可選擇多個檔案
- Source = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls; *.xlsx),*.xls;*.xlsx", _
- MultiSelect:=True)
- If TypeName(Source) = "Boolean" Then If Source = False Then Exit Sub
- For Each f In Source
- '開啟檔案/活頁簿
- With Workbooks.Open(f)
- '對所有工作表
- For i = 1 To ActiveWorkbook.Sheets.Count
- '複製工作表到本活頁簿
- .Sheets(i).Copy after:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
- '本活頁簿中該工作表
- With ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
- '依land_no_m, land_no_c欄排序
- If Not IsError(Application.Match("land_no_m", .Rows(1), 0)) Then .[A1].CurrentRegion.Sort Key1:=.Columns(Application.Match("land_no_m", .Rows(1), 0)), Order1:=xlAscending, Header:=xlYes
- If Not IsError(Application.Match("land_no_c", .Rows(1), 0)) Then .[A1].CurrentRegion.Sort Key1:=.Columns(Application.Match("land_no_c", .Rows(1), 0)), Order1:=xlAscending, Header:=xlYes
-
- '找出不符合的欄
- For j = 1 To .[A1].CurrentRegion.Columns.Count
- If IsError(Application.Match(.Cells(1, j).Value, Array("section", "SC", "LANDUSE", "PUBNO", "OPTION", "METHOD", "MUPLAN", "DUPLAN", "ORG_FID"), 0)) Then
- If rng Is Nothing Then Set rng = .Columns(j) Else Set rng = Union(rng, .Columns(j))
- End If
- Next j
- '刪除
- .Range(rng.Address).Delete shift:=xlToLeft
- Set rng = Nothing
- End With
- Next i
- '關閉檔案
- .Close
- End With
- Next f
- End Sub
複製代碼 |
|