- 帖子
- 522
- 主題
- 36
- 精華
- 1
- 積分
- 603
- 點名
- 0
- 作業系統
- win xp sp3
- 軟體版本
- Office 2003
- 閱讀權限
- 50
- 性別
- 男
- 註冊時間
- 2012-12-13
- 最後登錄
- 2021-7-11
|
3#
發表於 2014-4-17 11:37
| 只看該作者
回復 2# s7659109
試試看:
 - Option Explicit '強制宣告變數
- '刪除
- Private Sub CommandButton1_Click()
- Dim sh1, sh2 As Worksheet
- Set sh1 = Sheets("來源")
- Set sh2 = Sheets("結果")
-
- sh2.[H1] = sh1.[H1]
- sh1.[I1] = "=MATCH(H1,A:A,0)"
- sh2.[I1] = "=MATCH(H1,A:A,0)"
-
- '刪除"來源"
- If Application.IsNumber(sh1.[I1]) Then
- sh1.Rows(sh1.[I1]).Delete
- End If
-
- '刪除"結果"
- If Application.IsNumber(sh2.[I1]) Then
- sh2.Rows(sh2.[I1]).Delete
- End If
- End Sub
- '
- '新增一筆
- Private Sub CommandButton2_Click()
- Dim sh1, sh2 As Worksheet
- Dim lastRow1, lastRow2 As Integer
- Set sh1 = Sheets("來源")
- Set sh2 = Sheets("結果")
-
- lastRow1 = sh1.[A65536].End(xlUp).Row '取得 "來源"欄A最下面非空白列 的列號
- lastRow2 = sh2.[A65536].End(xlUp).Row + 1 '取得"結果"欄A最下面非空白列 的下一列的列號
-
- '將"來源"的新資料複製到"結果"
- sh1.Cells(lastRow1, 1).Resize(1, 3).Copy sh2.Cells(lastRow2, 1)
- End Sub
複製代碼 當來源被刪除時.xls
http://www.mediafire.com/download/2krzi85li7i3npi/%E7%95%B6%E4%BE%86%E6%BA%90%E8%A2%AB%E5%88%AA%E9%99%A4%E6%99%82.7z |
|