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.
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
GetCharArrayfunction parses the text of the string you pass it to return that text as an array of characters (even though BA doesn’t have achartype just astringtype so I am returning a string. Same idea)Then given that we can call
GetNumberFromCharsto get the50fromVL50sand callGetLeftMostLettersto get theVLfromVL50s.Then is some worksheet I made a named range called
keyswhere 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 likeWe can use the
vlookupworksheet function with theRange("keys")and the result ofGetLeftMostLettersto find the number that should be added to the result ofGetNumberFromChars.So it can be used as such…