s
s
aiks
ls
s
s
s
ehk
s
s
os
s
ns
s
s
s
s
aiks
ls
s
s
s
ehk
s
s
os
s
ns
s
s
I have that on a1 as raw data , i want the macro to delete all consonants and remains with vowels
------------------Deleted
Last edited by Sintek; 04-09-2017 at 11:02 AM. Reason: Found error in code
Good Luck...
I don't presume to know what I am doing, however, just like you, I too started somewhere...
One-day, One-problem at a time!!!
If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
Also....Add a comment if you like!!!!
And remember...Mark Thread as Solved...
Excel Forum Rocks!!!
5B:
![]()
Sub Test() With CreateObject("VBScript.RegExp") .Global = True .Ignorecase = True .Pattern = "[^a|e|i|o|u|\n]" If .Test([A1]) Then [C1] = .Replace([A1], "") End With End Sub
1. I care dog
2. I am a loop maniac
3. Forum rules link : Click here
3.33. Don't forget to mark the thread as solved, this is important
@ karedog
Please put me out of my misery.....Assume that the information was in Column A1 down and not just in A1 so i.e A1 = "s", A2 = "s" A3 = "aiks" etc
How does this code have to be altered to work.
![]()
Option Explicit Sub Cons_Del() Dim n As Long Dim i As Integer Dim lRow As Long lRow = Range("A" & Rows.Count).End(xlUp).Row For i = 1 To lRow For n = 1 To Len("A" & i) If Not Range("A" & i).Characters(n, 1).Text Like "[a,e,i,o,u]" Then Range("A" & i).Characters(n, 1).Text = "" End If Next n Next i End Sub
Hi Norie
the characters in the string in Range("A" & i)
@ karedog
I was trying to make use of MickG's code for the post problem and could not even get that to work.
![]()
Option Explicit Sub MickGCode() Dim n For n = 1 To Len([a1]) If Not Range("A1").Characters(n, 1).Text Like "[a,e,i,o,u]" Then Range("A1").Characters(n, 1).Text = "" End If Next n End Sub
Are you sure you should be using Len("A" & i) in the inner loop?
If posting code please use code tags, see here.
@ Norie
I dunno...I'm lost....Being trying to figure out why !!!!
I'm trying to loop through A & i then loop through the characters of A & i
Is it the characters in the string A & i you want to loop through or the characters in the string in Range("A" & i)?
PS When deleting it's normally a good idea to loop backwards.
Oh my gosh...Really....Still so much to learn...Would never have figured that out...
So code that works if info was in column...Thanks Norie
![]()
Option Explicit Sub Cons_Del() Dim n As Long Dim i As Integer Dim lRow As Long lRow = Range("A" & Rows.Count).End(xlUp).Row For i = 1 To lRow For n = Len(Range("A" & i).Value) To 1 Step -1 If Not Range("A" & i).Characters(n, 1).Text Like "[a,e,i,o,u]" Then Range("A" & i).Characters(n, 1).Text = "" End If Next n Next i End Sub
And MickG's code to solve the thread problem
![]()
Option Explicit Sub MickGCode() Dim n For n = Len([a1]) To 1 Step -1 If Not Range("A1").Characters(n, 1).Text Like "[a,e,i,o,u]" Then Range("A1").Characters(n, 1).Text = "" End If Next n End Sub
So this,
should be this.![]()
Len("A" & i)
![]()
Len(Range("A" & i).Value)
This UDF might work
![]()
Function RemoveCharacters(ByVal aString As String, Optional Characters As String, Optional CaseSensitive As Boolean = False) As String If Characters = vbNullString Then Characters = "bcdfghjklmnpqrstvwxyz" & "BCDFGHJKLMNPQRSTVWXYZ" End If Dim myChr As String: myChr = Chr(5) Dim strTest As String Dim workPoint As Long strTest = aString If Not CaseSensitive Then Characters = LCase(Characters) strTest = LCase(strTest) End If workPoint = 1 Do Until workPoint > Len(strTest) Do While Mid(strTest, workPoint, 1) Like "[" & Characters & "]" Mid(strTest, workPoint, 1) = myChr Mid(aString, workPoint, 1) = myChr strTest = Replace(strTest, myChr, vbNullString) aString = Replace(aString, myChr, vbNullString) Loop workPoint = workPoint + 1 Loop RemoveCharacters = aString End Function
_
...How to Cross-post politely...
..Wrap code by selecting the code and clicking the # or read this. Thank you.
@sintek,
Sorry for the late, but I see you have figured it out by yoursef. Good job.![]()
What is the final version , to pick , that will do the needful
I would go for this one.
![]()
Sub Test() With CreateObject("VBScript.RegExp") .Global = True .Ignorecase = True .Pattern = "[^aeiou\n]" If .Test([A1]) Then [C1] = .Replace([A1], "") End With End Sub
Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks