+ Reply to Thread
Results 1 to 4 of 4

Convert Substitute Function in Excel to VBA code

  1. #1
    Registered User
    Join Date
    07-11-2014
    Location
    Pennsylvania
    MS-Off Ver
    2010
    Posts
    5

    Convert Substitute Function in Excel to VBA code

    We have a barcode that we are scanning into an input screen, the barcode always has from 2 to 5 leading zeros followed by non zero numbers. I need to strip out the leading non zero numbers from the string.

    We have been using the following Excel formula to the same process for a text string in a worksheet and it works great to find the string position for the first non leading zero and then we use mid to extract the trailing number.

    =Find(Mid(Substitute(A1,0,""),2,1),A1)-1

    Would love some help on VBA code, or, functions that can accomplish the same thing in macro. I tried the following (was just showing the position in a MSGBOX for testing purposes) but there is no Substitute function in VBA.

    Dim ITM_NUM As Variant
    Dim NUM_POS As Integer
    ITM_NUM = InputBox("Scan Item Number")
    NUM_POS = Find(Mid(Substitute(ITM_NUM, 0, ""), 2, 1), ITM_NUM) - 1
    MsgBox NUM_POS


    Thanks

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Convert Substitute Function in Excel to VBA code

    Hi

    I would think that all you have to do is multiply by 1.

    Please Login or Register  to view this content.


    Or in Excel

    =A1*1

    or you will normally see:-

    =--A1


    if you have a lot of Similar numbers in Column A then try this Macro:


    Please Login or Register  to view this content.
    Last edited by mehmetcik; 03-15-2019 at 01:40 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Registered User
    Join Date
    07-11-2014
    Location
    Pennsylvania
    MS-Off Ver
    2010
    Posts
    5

    Re: Convert Substitute Function in Excel to VBA code

    Thanks! Such a simple solution (simple solutions are usually the ones that elude me).

    I had to tweak the code a bit to work for my situation but it did exactly what I needed it to!

  4. #4
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Convert Substitute Function in Excel to VBA code

    2 cents for learning purposes... VBA uses Replace rather than substitute
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

+ 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. Replies: 10
    Last Post: 02-20-2018, 10:02 AM
  2. Convert Excel Code to Access Code
    By Ruseju in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-17-2016, 02:36 AM
  3. [SOLVED] Convert nested if function to vba code
    By HerryMarkowitz in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 01-31-2015, 09:56 AM
  4. Replies: 4
    Last Post: 10-28-2014, 11:04 PM
  5. Replies: 8
    Last Post: 05-14-2013, 12:36 AM
  6. [SOLVED] Substitute function in Excel
    By bjnockle in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-07-2013, 08:26 PM
  7. [SOLVED] how to convert the vlookup function to vba code
    By funtastic in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-04-2012, 06:50 PM

Tags for this Thread

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