Determine if cell contains number/letters

micro-blades

Board Regular
Joined
Feb 20, 2007
Messages
91
Hi,

I am copying cell values from one column to another using VBA. I can do the copy/paste fine I just need to determine if what I am pasting contains a letter so I can determine what column to copy to. The cells all contain numbers so I will only need to seperate numbers combined with letters.

I need to do the opposite for another column but I need to determine if cells containing letters have any numbers and place them in the proper column.

Any ideas?

Thanks,
Brian
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Clue: If you add a 0 to the value in the cell, it will give you a numeric result if the value is all numbers. If any letters exist in the value, then you will get an error.


e.g. if A1 = 12345, Then A1+0 = 12345

if A1 = 123ABC, then A1+0 gives #VALUE! error

therefore: Formula= If(isnumber(A1+0),"numeric","non-numeric")
 
Upvote 0
Thanks, that works, but how to use it in a macro?

I want to use an If statement to determine if the active cell is in column F, then determine if the data in cell A2 contains a letter (ie. some data is 22 which contains no letter, other data is 2VSV, which contains letters), if so I will then move the selection one cell to the right and paste A2's data there. If it doesn't contain a letter I will paste it to the current active cell.

I'm really struggling getting the If statement to work but that's really another subject. If you can at least explain how I get your formula to work within the macro that would be great.

Thanks
Brian
 
Upvote 0
Something like

Code:
Dim X As Variant, bVal As Boolean
X = Range("A1").Value
bVal = IsNumeric(X)
If bVal Then
'code
Else
'other code
End If
 
Upvote 0
Also, the reason I added +0, where you could probably leave it out, is that in most cases where there are combinations of numerics, texts and text/numeric, the format of everything is usually text... the +0 forces numbers to be numbers and the rest not....so you may need to add 0 to this line:

Code:
X = Range("A1").Value

i.e.
Code:
X = Range("A1").Value + 0
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,251
Members
448,556
Latest member
peterhess2002

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