Macro to find and store the last words in a text string

rockja

New Member
Joined
Dec 14, 2010
Messages
7
Hi, I am formatting an exported Excel report from another program using a macro. I need to extract the project name which is at the end of a text string. It needs to be stored as a defined variable to be used and called upon later.

For instance:

Project Name of cell A1 would be = ProjName

The text string is always stored in cell A1 and looks like this:

"Current Solution Summary Report Project: Project Name"; where 'Project Name' will always be different. The the first five words "Current Solution Summary Report Project:" will always be the same.

Thanks!
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Code:
ProjName = replace(Range("A1").Text,"Current Solution Summary Report Project: ","")

Cheers

Dan
 
Upvote 0
Welcome to MrExcel board...


try this

Code:
Sub projname()
Dim projname As String
projname = Mid(Range("A1"), InStr(Range("A1"), ":") + 2, Len(Range("A1")) - InStr(Range("A1"), ":"))

End Sub
 
Upvote 0
Code:
Sub test()
Dim ProjName As String
ProjName = Split(Range("A1"), ":")(1)
MsgBox ProjName
End Sub
 
Upvote 0
Thanks Blade Hunder/Dan and texasalynn!

Dan, I was just typing a reply saying thank you, the code worked perfectly! texasalynn, I appreciate your solution as well, and thanks for the welcoming to MrExcel Board. This has been a great first experience using forums!

Thanks,
-Jason
 
Upvote 0
or

Code:
ProjName = Evaluate("=MID(A1,42,255)")

edit: Whoa I am sure there weren't all those replies a second ago!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,792
Messages
6,174,608
Members
452,574
Latest member
hang_and_bang

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