Board logo

標題: [發問] 選取範圍後,將儲存格為0的刪除 [打印本頁]

作者: abc9gad2016    時間: 2021-4-22 17:44     標題: 選取範圍後,將儲存格為0的刪除

請教各位前輩,小弟是VBA新手
需求是選取某固定範圍後,偵測數字為0的話,則將該範圍內的儲存格清空

用網路上的範例修改後,出現以下錯誤,還請前輩幫忙 謝謝

Sub 選取範圍清除0()
Dim Rng As Range, xCell As Range
Dim xRows As Integer
xTitleId = "清除0"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("選取範圍清除0", xTitleId, WorkRng.Address, Type:=8)
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Range("Rng").Select
If Rng = 0 Then
Range("Rng").ClearContents
End If
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
作者: samwang    時間: 2021-4-23 08:20

回復 1# abc9gad2016

請測試看看,謝謝。

Sub 選取範圍清除0()
Dim Rng As Range, xCell As Range
Dim xRows As Integer
xTitleId = "清除0"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("選取範圍清除0", xTitleId, WorkRng.Address, Type:=8)
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each Rng In WorkRng
    If Rng = 0 Then Rng.ClearContents
Next

Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
作者: abc9gad2016    時間: 2021-4-23 15:29

回復  abc9gad2016

請測試看看,謝謝。

Sub 選取範圍清除0()
Dim Rng As Range, xCell As Range
D ...
samwang 發表於 2021-4-23 08:20



   謝謝sam大,可以




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)