Re: Macro To Delete The First Two Characters Of A Cell
Quote from edelauna
what does mid and split do?
Copying the code, putting the cursor on the appropriate word and pressing F1 gets you an answer much faster than posting this sort of question here, however, from Help:
[COLOR="Gray"]Mid Function
Returns a Variant (String) containing a specified number of characters from a string.
Syntax
Mid(string, start[, length])
The Mid function syntax has these named arguments:
string Required. String expression from which characters are returned. If string contains Null, Null is returned.
start Required; Long. Character position in string at which the part to be taken begins. If start is greater than the number of characters in string, Mid returns a zero-length string ("").
length Optional; Variant (Long). Number of characters to return. If omitted or if there are fewer than length characters in the text (including the character at start), all characters from the start position to the end of the string are returned.[/COLOR]
In this case it effectively removes the first 2 characters from a string, start being 3.
Again from Help:
[COLOR="Gray"]Split Function
Returns a zero-based, one-dimensional array containing a specified number of substrings.
Syntax
Split(expression[, delimiter[, limit[, compare]]])
The Split function syntax has these named arguments:
expression Required. String expression containing substrings and delimiters. If expression is a zero-length string(""), Split returns an empty array, that is, an array with no elements and no data.
delimiter Optional. String character used to identify substring limits. If omitted, the space character (" ") is assumed to be the delimiter. If delimiter is a zero-length string, a single-element array containing the entire expression string is returned.
[/COLOR]
The expression above is, in this case, the result of the Mid function while the delimiter is "-", the minus sign.
Quote from edelauna
My other problem is there is a double digit I would only like to delete one character?
The strings you supplied both had double digits. Could you be specific about what you mean here please. Which double digits do you mean? Which single character do you want deleted. I am neither a mind reader, nor can I see over your shoulder.
Quote from edelauna
.. is there some way to make the characters I want a variable?
Well, the result of the Split function is to result in an array with 2 members, x(0) and x(1), being (in the case of the string you supplied "| 12- 4") "12" and " 4" respectively. So you have your variables.
Quote from edelauna
x = Split(Mid(Cells(lrow, "E").Value, 3), "-")
Cells(lrow, "F") = x(0) + x(1) / 12
This code does not work?
I don't understand the question mark at the end. Have you tried the code? It certainly worked for the two strings you supplied, yielding 12.3333333 and 60.91666667
p45cal