Forum

replace blank with ...
 
Notifications
Clear all

replace blank with macro vba code

4 Posts
2 Users
0 Reactions
66 Views
 m m
(@coral)
Posts: 10
Active Member
Topic starter
 

hi
i want a vba macro code for finding

#DIV/0!
divide by zero error

in one column (R2:R20) and then put blank instead of it , i have many sheets and i have to repeat this action for all so it will be better to do it with vba code

please help to find correct syntax

Sub RepUnd()

Columns("R").Replace "*/0", "":

End Sub

 
Posted : 12/05/2020 3:18 am
(@purfleet)
Posts: 412
Reputable Member
 

THis piece of code will look in the selected range and replace a div error it ignores any other text or errors as far as i can see

Sub ReplaceDivError()

Dim r As Range
Dim c As Range

Set r = Selection

For Each c In Selection
Debug.Print c.Address

If IsError(c.Value) Then
If c.Value = CVErr(xlErrDiv0) Then
c.Value = ""
End If
End If
Skip:
Next c

End Sub

 
Posted : 12/05/2020 8:57 am
 m m
(@coral)
Posts: 10
Active Member
Topic starter
 

hi 

first of all thank you for your help

 and could you please change code a bit ( Set r = Selection)

selection have to be constant :R2 up to maximum  R50 

 
Posted : 12/05/2020 1:07 pm
(@purfleet)
Posts: 412
Reputable Member
 

You only want to look in column R? Sorry missed that bit

just change the selection to

set r = range("r2:r50")

Or if you want to make it dynamic as column r gets longer

Sub ReplaceDivError()

Dim r As Range
Dim c As Range
Dim lr As Integer

lr = Cells(Rows.Count, "r").End(xlUp).Row
Set r = Range("r2:r" & lr)

For Each c In r

If IsError(c.Value) Then
If c.Value = CVErr(xlErrDiv0) Then
c.Value = ""
End If
End If

Next c

End Sub

 
Posted : 13/05/2020 12:38 am
Share: