- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
回復 2# pegawang
也可如此寫法- Option Explicit
- Sub Ex() 'Sub Find() :Find 是VBA專屬的文字程式的名稱避免使用
- Dim FindString As String
- FindString = InputBox("請輸入數值")
- If FindString <> "" Then
- With Range("E1:I3000")
- .Cells.Replace FindString, "=1/0", xlWhole '**輸入的文字替換為錯誤值
- On Error Resume Next '**不理會程式上的錯誤,繼續執行程式
- With .SpecialCells(xlCellTypeFormulas, xlErrors) '**沒有錯誤值, 程式會錯誤而中斷
- If Err = 0 Then
- .Parent.Cells.Interior.ColorIndex = xlNone
- .Value = FindString
- .Interior.ColorIndex = 4
- Else
- MsgBox "找不到 " & FindString
- End If
- End With
- End With
- End If
- End Sub
複製代碼 |
|