LENDIEN聯電 冷暖 清淨 除溼 移動式空調 9000BTU任天堂-Switch-NS-公司貨主機-豪華全配組LG樂金 WIFI遠控雙眼小精靈掃地清潔機器人變頻版
顯示具有 office 標籤的文章。 顯示所有文章
顯示具有 office 標籤的文章。 顯示所有文章

2009年6月29日 星期一

用excel巨集刪除重複資料

這是今天做的,感覺挺實用。

=================================================
Sub DelDups_TwoLists()
Dim iListCount As Integer
Dim iCtr As Integer
Dim sheetA_Name As String
Dim sheetB_Name As String
Dim sheetA_Range As String
Dim sheetB_Range As String

' Turn off screen updating to speed up macro.
Application.ScreenUpdating = False

sheetA_Name = Sheets("rule").Cells(1, 1)
sheetA_Range = Sheets("rule").Cells(1, 2)
sheetB_Name = Sheets("rule").Cells(2, 1)
sheetB_Range = Sheets("rule").Cells(2, 2)

' Get count of records to search through (list that will be deleted).
iListCount = Sheets(sheetA_Name).Range(sheetA_Range).Rows.Count

' Loop through the "master" list.
For Each x In Sheets(sheetB_Name).Range(sheetB_Range)
' Loop through all records in the second list.
For iCtr = 1 To iListCount
' Do comparison of next record.
' To specify a different column, change 1 to the column number.
If x.Value = Sheets(sheetA_Name).Cells(iCtr, 1).Value Then
' If match is true then delete row.
Sheets(sheetA_Name).Cells(iCtr, 1).Delete xlShiftUp
' Increment counter to account for deleted row.
iCtr = iCtr + 1
End If
Next iCtr
Next
Application.ScreenUpdating = True
MsgBox "Done!"
End Sub
=================================================

程式其實是從M$網站上co下來的,只改了資料來源設定方式
sheetA_Name,sheetA_Range分別是母資料的sheet名稱跟資料範圍
sheetB_Name,sheetB_Range分別是子資料的sheet名稱跟資料範圍
這四個值透過rule這個sheet的A1,B1,A2,B2來設定,然後巨集執行後,就會把母資料的欄位中跟子資料重複的資料刪掉。

不過執行時間比原先預期的要久,才少少三千多筆的母資料跟八百多筆的子資料,跑這個巨集就要一分多鐘的時間,真的相當出乎意料啊!

如果資料再多個兩三倍,不知道要不要搞來一台超級電腦?

2009年1月19日 星期一

Excel照相機

今天忽然要用找不到去那加,找了一下文章終於搞定。又是一篇KM

1.點選「工具」→「自訂」
2.選「指令」標籤頁→在類別選單裡點選「工具」→在右邊指令裡點選「攝影」(不要放)→點著攝影把它拉到現有工具列的任何位置
3.在工作表裡選取要拍下來的部份
4.點一下剛剛拉出來的攝影icon
5.在工作表的任一地方點一下,圖就跑出來了,搞定!

不過也不是每次都那麼順利。今天做的時候就有幾次照出來的圖怪怪的,然後就把資料縮小一點,重新調整一下位置,再照一次才成功。所以結論是照相機礙於「不夠廣角」,要拍的東西要整理一下才行。