ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro to Function (https://www.excelbanter.com/excel-programming/437558-macro-function.html)

K[_2_]

Macro to Function
 
The below macro works perfect. It extracts the name from a text. How
can I change below macro into "Public Function" Please can any friend
can help

Sub GetNames()
For Each Cell In Range("A1:A4")
Text = Replace(Split(Cell, "\")(UBound(Split(Cell, "\"))), ".", " ")
Parts = Split(Text, " ", 3)
Parts(2) = ""
Cell.Offset(0, 1).Value = Trim(Join(Parts))
Next
End Sub

Rick Rothstein

Macro to Function
 
It's a subroutine... exactly what do you mean by "change [it] to a public
**function**"?

--
Rick (MVP - Excel)


"K" wrote in message
...
The below macro works perfect. It extracts the name from a text. How
can I change below macro into "Public Function" Please can any friend
can help

Sub GetNames()
For Each Cell In Range("A1:A4")
Text = Replace(Split(Cell, "\")(UBound(Split(Cell, "\"))), ".", " ")
Parts = Split(Text, " ", 3)
Parts(2) = ""
Cell.Offset(0, 1).Value = Trim(Join(Parts))
Next
End Sub



K[_2_]

Macro to Function
 
basically i need function to exctract name from text


Rick Rothstein

Macro to Function
 
I don't remember your original data, but I think this function will do what
you want...

Function GetName(S As String) As String
Dim Parts() As String
GetName = Replace(Split(S, "\")(UBound(Split(S, "\"))), ".", " ")
Parts = Split(GetName, " ", 3)
Parts(2) = ""
GetName = Trim(Join(Parts))
End Function

--
Rick (MVP - Excel)


"K" wrote in message
...
basically i need function to exctract name from text



K[_2_]

Macro to Function
 
Thanks lot rick


All times are GMT +1. The time now is 12:42 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com