if text and if number in a cell then.. Please help.

Teladianium

New Member
Joined
Apr 10, 2012
Messages
15
Hi all. I have a dilemma I hope you can help me with. I am not great at VBA so bare with me. I need a macro that will look in an individual cell and work out what to do with its contents. There could be a number, or a text and a number. the column is essentially serial numbers. for eg.

item 123
23456789
item 345
serial 56789

I need the macro to look to see if it is an item, a serial or just a number and depending on what it is do something.

eg. "item 123" would be added to a different workbook, the cell value would be split into 2 cells. one column "type" and the other "number". the "serial 56789" would follow the same pattern but to different cells and the number "23456789" would be placed in a cell according to character count.


Hope this makes sense. and thank you
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Just for info...
There could be a number, or a text and a number.
there are only 2 types of data in excel, numeric (only numbers) and text (only text or any combo of text and numbers). So as far as excel is concerned, 123456 is a number, and abc or abc123 or 123abc are all text. That is not to say that telling the difference between 1 type of text is not possible.

If you only have those 2 (or maybe a few more), you could test for =IF(ISNUMBER(SEARCH("item",A1,1)),do-this, do-that)
 
Upvote 0
Brilliant, thanks Ford.

Wanted to keep it all vba, so I have use vba to insert and remove the formulae and it works great. I had numerical returns for the "do-this, do-that" and will assign the job to the number. thanks again
 
Upvote 0
Happy to help :)

You could add an extra test - along the same lines - to test for "serial"
 
Upvote 0
Thanks,

This is the line I used =IF(ISNUMBER(SEARCH("item",H10,1)),"1", IF(ISNUMBER(SEARCH("serial",H10,1)),"2", "3") ) so I get a 1, 2 or 3 for item, serial, on just a number. Then I use the macro to se the value and then run the correct macro for each one. Im not to good ad vba and usually keep it simple, but learning all the time. Thanks again, a real help
 
Upvote 0
=IF(ISNUMBER(SEARCH("item",H10,1)),"1", IF(ISNUMBER(SEARCH("serial",H10,1)),"2", "3") )
If what you have works and you are happy with it that's fine, but if the only text options are "item" or "serial" before a number then your formula could be simplified to

=IF(LEFT(H10,1)="i",1,IF(LEFT(H10,1)="s",2,3))
 
Last edited:
Upvote 0
I like Pete's suggestion better, especially if there will only be 2 (of only 1 starting with I and 1 starting with S) to test for. Also, it would be better if you did not wrap the 1, 2, 3 etc in "" otherwise excel will treat them as text
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top