Writing a function to remove vowels from a string

Kavindra

New Member
Joined
Apr 3, 2013
Messages
2
Hi all,

I have written this tiny snippet. Could you look into as to why it does not return any results

Code:
Function removow(Val As String) As String

Dim length As Integer


Dim Concat As String


Dim Cntr As Integer


Cntr = 1


length = (Len(Val))


While Cntr <= length




    If Mid(Val, Cntr, 1) <> "a" And Mid(Val, Cntr, 1) <> "e" And Mid(Val, Cntr, 1) <> "i" And Mid(Val, Cntr, 1) <> "o" And Mid(Val, Cntr, 1) <> "u" Then
    
    Concat = Concat & Mid(Val, Cntr, 1)
    
    End If
    
Cntr = Cntr + 1


Wend


End Function

Thanks a lot guys.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
I hadn't assigned the removow = Concat. It's working now.

It was my first post. :D

See you later.
 
Upvote 0
You never set the return value for the function.

Try adding this.
Code:
removow  = Concat
 
Upvote 0
Or using in built worksheet functions

Code:
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(UPPER(A1),"A",""),"E",""),"I",""),"O",""),"U","")
 
Upvote 0
You need a linew to return the value to the function , as below:-
Rich (BB code):
Wend
    removow = Concat
End Function

Another option:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG03Apr53
[COLOR="Navy"]Dim[/COLOR] n
   [COLOR="Navy"]For[/COLOR] n = 1 To Len([a1])
       [COLOR="Navy"]If[/COLOR] Range("A1").Characters(n, 1).Text Like "[a,e,i,o,u]" [COLOR="Navy"]Then[/COLOR]
          Range("A1").Characters(n, 1).Text = ""
        [COLOR="Navy"]End[/COLOR] If
    [COLOR="Navy"]Next[/COLOR] n
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,203,071
Messages
6,053,375
Members
444,658
Latest member
lhollingsworth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top