Extract numbers that occur before specific phrases

  • Hi,

    I'm a beginner in VBA and I'm trying to extract different numbers which will always occur after a specific phrase in a string.

    The string looks like below (but can vary according to the products that are bought). It's a list of products that has been bought by a client with quantities before.



    I would like to extract the number before each product and put it in a specific column. The output would like below :




    The length of the numbers will vary. The list of products as well. That's why I can't do a split and the macro needs to find the specific text in the string to extract the right number and place it inthe right column.

    • Best Answer

    Try this

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

    Edited once, last by KjBox ().

  • Hi KjBox,


    Thanks a lot. I've tried, but i got the message "Object required". I'll try to solve this problem to be able to run the macro and I'll keep you updated.

    Thanks again

  • Which line of code is highlighted if you click "Debug" on the error message?

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Hi again,


    My bad ?( , as my excel is in French, I forgot to change Sheet1 in Feuil1.


    The macro works perfectly, ton of thanks for your precious support !


  • You're welcome

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!