Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 07-09-2018, 11:33 AM
ArviLaanemets ArviLaanemets is offline set variable for string after first underscore Windows 8 set variable for string after first underscore Office 2016
Expert
 
Join Date: May 2017
Posts: 949
ArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant futureArviLaanemets has a brilliant future
Default

The worksheet formula is like (assumed the text is in cell A2, on fly)
Code:
=IFERROR(RIGHT(A2,Find("_",A2)), A2)
Sorry! With Office 2010
Code:
=IF(ISERROR(RIGHT(A2,Find("_",A2)-1)), A2,RIGHT(A2,Find("_",A2)))
When you need this in VBA, then instead FIND() you have to use InStr(), and If ... End If to handle cases when the string is not found (then InStr() returns 0).
Something like:
Code:
If InStr(SourceVariable, "_") = 0 Then
     ResultVariable = SourceVariable
Else
     ResultVariable = Right(SourceVariable, Len(SourceVariable) - InStr(SourceVariable, "_"))
End If
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
set variable for string after first underscore Assigning a string variable to a userform label caption Larry_1 Excel Programming 3 12-18-2017 06:59 AM
I want to create a bar chart of multiple variable. Then I need to draw trend lin of those variable shimulsiddiquee Excel 1 05-16-2017 07:39 AM
Emails to recipients with underscore in email address not received gjskerritt Outlook 0 03-14-2017 06:27 PM
Run Time Error '91': Object variable or With block variable not set using Catalogue Mailmerge Berryblue Mail Merge 1 11-13-2014 05:36 PM
set variable for string after first underscore Why unable to use underscore in microsoft word styles( user defined)? noufalcm Word 1 03-08-2011 01:46 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:04 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft