+ Reply to Thread
Results 1 to 6 of 6

VBA Find String before specific character in string

  1. #1
    Forum Contributor
    Join Date
    08-14-2016
    Location
    Warrington, England
    MS-Off Ver
    MS 365
    Posts
    168

    VBA Find String before specific character in string

    Hi all,

    I have a ComboBox which upon UserForm initialize should search a a TextBox and always find the string before " - ". The Textbox will either be empty or always have a string of text in it separated by " - ". For example if the TextBox has "Action Alert - Imminent Due Date". Upon UserForm opening the ComboBox will populate with Action Alert as it has found all string before " - ".

    This is so that the ComboBox will find any string, no matter how short or long before " - ".

    Here is my code so far:

    Please Login or Register  to view this content.
    Excel Beginner

  2. #2
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,150

    Re: VBA Find String before specific character in string

    Check this;

    Please Login or Register  to view this content.
    Last edited by Haluk; 02-25-2019 at 05:33 AM.

  3. #3
    Forum Contributor
    Join Date
    08-14-2016
    Location
    Warrington, England
    MS-Off Ver
    MS 365
    Posts
    168

    Re: VBA Find String before specific character in string

    Hi, thanks for the response, i have tried to adapt the code provided but can't seem to get it work, the textbox can contain any string prior to " - " so will not always be Action Alert, so need a more dynamic code. Here is my code below:

    Please Login or Register  to view this content.
    If my textbox does not equal nothing then my combobox should equal the string before " - " in Column F in the active cell row. For example if my active cell is D5 and in F5 there is a string which is REF1234 - Delivered then the combobox would equal "REF1234"

  4. #4
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: VBA Find String before specific character in string

    Small change:

    Please Login or Register  to view this content.
    Rory

  5. #5
    Forum Contributor
    Join Date
    08-14-2016
    Location
    Warrington, England
    MS-Off Ver
    MS 365
    Posts
    168

    Re: VBA Find String before specific character in string

    Hi Rorya, thanks for the help, this worked perfectly, now how would i do the opposite if i wanted the code to find all string after "-"?

  6. #6
    Forum Contributor
    Join Date
    08-14-2016
    Location
    Warrington, England
    MS-Off Ver
    MS 365
    Posts
    168

    Re: VBA Find String before specific character in string

    Nevermind i just figured it out! Many thanks for your help. Marked as resolved and rep added

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Loop through a string and find the character/string need
    By dluhut in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 07-15-2014, 11:51 AM
  2. Replies: 23
    Last Post: 05-19-2014, 09:45 PM
  3. [SOLVED] Find text left or right of a specific character in a text string
    By Locopete99 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-14-2014, 05:55 AM
  4. [SOLVED] deleting a specific character in a string
    By FieldHaven in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-10-2014, 12:18 PM
  5. [SOLVED] find the character position in a string of the last occurrence of a nominated character
    By jmac1947 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-04-2014, 11:52 PM
  6. Replies: 2
    Last Post: 06-16-2010, 09:01 AM
  7. Replies: 3
    Last Post: 04-17-2010, 05:02 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1