Excel vba if first char of cell is 1 then

Closed
Bill - Aug 18, 2008 at 01:04 PM
 Not a member yet. - Nov 23, 2010 at 12:01 PM
Hello,

I have a question about "if then" in excel vba

I've been looking all over the web for an answer or example and now matter what code I try I cannot get the right syntax.

I have a column named "code" which contains item codes and I want to test the value and place a particular value in another cell based on the comparison.

Allow me to illustrate.

Code
1AALIBOLTS10000


now, I want to be able to look at the first char of cell A1 and if it is a "1" then place "its a 1" into column b cell 1

then I need to check the second char of cell A1 and if it is a "C" then place "its a C" into column e cell 1

and so on and so on until I have compared all the values I wish to compare.

I hope this makes sense. I've been pulling my hair out trying to get this accomplished.

Any help would be greatly appreciated!

Thanks,

Bill
Related:

3 responses

the code for your question will look something like this.

Dim mycheck as boolean

endrange = range("A65000").end(xlUp).row

for I = 1 to endrange

mycheck = range("A" & i).value Like "1*"

if mycheck = true then

range("B" & i).value="Its a One"
end if

my2check = range("A" & i).value Like "?c*"

if my2check = true then

range("E" & i).value="Its a C"
end if

next I



Hope it helps. :)
Thanks so much, this is handy for the piles of things with zeros I must process.
0