Saturday, June 26, 2010

UDF to extract right most word of a cell


If you want to extract right most word from a cell. Try this udf-



Function last_word(str1 As String)
    
    Dim arr1
    arr1 = Split(str1, " ")
    last_word = arr1(UBound(arr1))

End Function


Steps to Use

  • Copy the below code
  • Press Alt+F11 to open VBA editor
  • Paste it in any public module or module 1
  • For example you want to extract right most word  from cell A1 in Cell B1 . In B1 = last_word(A1)

No comments:

Post a Comment

Import data from SQL

Macro to import data from SQL using ADO connection string: Sub Import_data_from_SQL() ' Tools -> References -> Microsoft Active...