PDA

View Full Version : Solved: Renaming cells



Klartigue
09-19-2011, 09:34 AM
Sub Vrus()
' Fill N/A with vrus

Dim cll As Range, rng As Range
Set rng = Range("E2" & Cells(Rows.Count, "E").End(xlUp).Row)
For Each cll In rng
If cll.Value = "#N/A" Then cll.Value = "vrus"
Next cll
End Sub


In this macro, I am trying to select cells in column E that have #N/A as a value and give them a new value "vrus." I thought my macro was correct but it doesn't seem to work. Does it look wrong to you?

Thanks for the help!

shrivallabha
09-19-2011, 10:38 AM
Try the following:
Sub Vrus()
' Fill N/A with vrus
Dim rng As Range
Set rng = Range("E2:E" & Cells(Rows.Count, "E").End(xlUp).Row)
For Each cell In rng
If Application.IsNA(cell.Value) = True Then cell.Value = "vrus"
Next cell
End Sub

Or another way:
Sub Vrus1()
' Fill N/A with vrus
Range("E2:E" & Cells(Rows.Count, "E").End(xlUp).Row).Replace What:="#N/A", Replacement:="vrus"
End Sub

Klartigue
09-19-2011, 11:03 AM
That works great!!!

Thank you!