Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8356145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:05:44+00:00 2026-06-09T10:05:44+00:00

I am new at excel VB and seek assistant in the following problem below:

  • 0

I am new at excel VB and seek assistant in the following problem below:

I have a column A with following values below:

column A
"VL50s"
"M50s"
"H50s"
"VL50s"
"H50s"

I would like to extract the numbers and run the following arithmetic function below into coloumn B.

key:
x is a number
VLx --> (x) + 1
Mx -->(x) + 2
Hx --> (x) + 3

the output should look like the following using the key above:

coloumn B
51
52
53
51
53

I would like to ask how would i go about doing this function in VBA. Thank you for your assistance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T10:05:46+00:00Added an answer on June 9, 2026 at 10:05 am

    Because you say the number of letter/number combos is much greater than in your example I think this is a problem for VBA and not a worksheet function. A WS function would become to hard to maintain and to beastly very quickly.

    I made these 4 functions. The GetCharArray function parses the text of the string you pass it to return that text as an array of characters (even though BA doesn’t have a char type just a string type so I am returning a string. Same idea)

    Then given that we can call GetNumberFromChars to get the 50 from VL50s and call GetLeftMostLetters to get the VL from VL50s.

    Then is some worksheet I made a named range called keys where column 1 of the range is letters like “VL”, “H”, “M” … and the corresponding value associated with it is in column 2. It would look like

    Col1    Col2
    VL      1
    M       2
    H       3
    ...     ...
    

    We can use the vlookup worksheet function with the Range("keys") and the result of GetLeftMostLetters to find the number that should be added to the result of GetNumberFromChars.

    Function GetNewNumber(inString As String) As Double
        Dim searchString As String, numberToAddFromKeys As Double, numberToAddToFromCell As Long, cellChars() As String
    
        cellChars = GetCharArray(inString)
        searchString = GetLeftMostLetters(cellChars)
        numberToAddToFromCell = GetNumberFromChars(cellChars)
    
        'use the keys named range where column 1 is your letters ("VL","H"...)
        'and column 2 is the corresponding value for that letter set
        numberToAddFromKeys = WorksheetFunction.VLookup(searchString, Range("keys"), 2, 0)
    
        GetNewNumber = CDbl(numberToAddFromKeys) + CDbl(numberToAddToFromCell)
    End Function
    
    
    Function GetNumberFromChars(inChars() As String) As Long
        Dim returnNumber As String, i As Long, numberStarted As Boolean
    
        For i = 1 To UBound(inChars)
            If IsNumeric(inChars(i)) Then
                If Not numberStarted Then numberStarted = True
                returnNumber = returnNumber & inChars(i)
            Else
                If numberStarted Then
                    'this will ignore that "s" on the end of your sample data
                    'hopefully that's what you need
                    GetNumberFromChars = returnNumber
                    Exit Function
                End If
            End If
        Next
    End Function
    
    Function GetLeftMostLetters(inChars() As String) As String
        Dim returnString As String, i As Long
    
        For i = 1 To UBound(inChars)
            If Not IsNumeric(inChars(i)) Then
                returnString = returnString & inChars(i)
            Else
                GetLeftMostLetters = returnString
            End If
        Next
    End Function
    
    
    Function GetCharArray(inText As String) As String()
        Dim s() As String, i As Long
        ReDim s(1 To Len(inText))
    
        For i = 1 To UBound(s)
          s(i) = Mid$(inText, i, 1)
        Next
        GetCharArray = s
    End Function
    

    So it can be used as such…

    Dim cell As Range, rng As Range
    'set this range to your actual range. 
    
    Set rng = Sheets("your sheet name").Range("A1:A5")       
    For Each cell In rng
        'put this resulting value wherever you want.
        Debug.Print GetNewNumber(cell.Value)
    Next cell
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem creating new instance of excel 2007 using VBA (from Access 2002).
I have made a new Excel 2010 Add-in project, with VS10. When I run
I'd like to create an Excel Add In. But I want it to have
I have to use OleDbConnection to create a new excel file, but when I
Every time I create a new excel sheet, I have to go in and
I'm using (and changing) an Excel-File from C#, like: Excel.Application app = new Excel.Application();
I have: Public Class ExcelProcess Private App As New Excel.Application Private Books As Excel.Workbooks
I would like to generate an Excel file using a database query in VB.Net.
I have the following in a program (written in VB.NET): Imports Microsoft.Office.Interop.Excel Public Class
I am very new to Excel and vba. I have an excel file that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.