PDA

View Full Version : Solved: VBA to replace specific alphabets with blanks



kevvukeka
04-26-2013, 07:36 AM
Hi All,

I am working in excel in 2010. I need help with the below code.

Out of given range I need to replace few alphabets with blanks. I dont know VBA but i searched and could gather few codes in to 1. But it shows a compile error for text1() variable. Can any help.

Below is my code.



Sub findreplace()


Dim i As String
Dim Default
Dim raypoints() As String
Dim text1() As
String, text2 As String
Default = "A,B,C,D,E,F,G,H"


i = InputBox("Letters to Remove", Default, Default)
text2 = ""


raypoints = Split(i, ",")


For text1 = 0 To UBound(raypoints)


With ActiveSheet.Selection


.Cells.Replace what:=text1, Replacement:=text2, LookAt:=xlPart,
_
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False,
_
ReplaceFormat:=False
End With
Next
text1





End Sub


Thanks & Regards,
Praveen

patel
04-26-2013, 10:30 AM
Sub findreplace()
Dim i As String, Default, raypoints() As String, text2 As String, t As Integer
Default = "A,B,C,D,E,F,G,H"
i = InputBox("Letters to Remove", Default, Default)
text2 = ""
raypoints = Split(i, ",")
For t = 0 To UBound(raypoints)
With Selection
.Replace what:=raypoints(t), Replacement:=text2, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End With
Next t
End Sub

kevvukeka
04-29-2013, 03:12 AM
Hi patel,

Thanks for the help. The code is working now as per my requirement. Thanks again.!!!!!!!!

Regards,
Praveen