is there any easy way to check for text?

Cath

Board Regular
Joined
Aug 10, 2005
Messages
156
Hi all

I have some data that is taken by macro into another spreadsheet, put in the right format, then it goes into access. For access it is essential that all the data is numeric NOT text. There will be lots of blanks in the data, this is fine, just as long as what there is, is numeric.

I've had a read around on the board and it seems there isn't a 'istext' in vba, but there is an 'isnumeric'

So the only way I can think to check it, is while moving the data, it loops through the columns of data, checking first to see if the cell is blank, then checking if the data is numeric, then warning the user if not.

However if I loop through it will give a warning every time it find some text. Which could be very annoying if by mistake the user has put in lots of text. Ideally I'd like it check through the whole lot, and then say at the end whether any text was found.

Can anyone think of a way to do this? I'm not asking anyone to write the whole code, just if its possible. (although no doubt I will be asking for more help once I start trying to write it!!)

Thanks for your time!!

:biggrin:
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hi Cath,

Using isNumeric, how about this as a starter:
Code:
Sub xxx()
Dim R As Range, vCur As Variant

For Each R In Range("A1:A10").SpecialCells(xlCellTypeConstants)
    vCur = R.Value
    If IsNumeric(vCur) Then
        'Do your thing here
    End If
Next R
End Sub

[Edit] - Note - to avoid accessing cells directly too much (performance issues), I set vCur to the current cell contents.
 
Upvote 0
you can use a boolean, (ie. dim anytextfound as boolean) and set it to true if there is any text found ( if not isnumeric(resultvalue) then anytextfound = true else exportvalue(resultvalue) ) assuming exportvalue is the function that exports it to access, and give an error message in the end if there is text found.

In addition, you can store the line numbers of the cells where the text is found in an array, and display it in the error message.

I hope this helps.

Regards,

Martien
 
Upvote 0
Hi

Thank, just had a go and that works, but if I put in the rest of my routine in the 'do your thing here' it will repeat it over and over again.

I move the data in blocks not individually as cells. And just to make things worse, i want to check for text down the columns, but I move the data in rows (there is text in every other column so I can't check the rows for text).

Cath
 
Upvote 0
Altering al_b_cnu his function, you would get a result looking like this:

Code:
Sub xxx() 
Dim R As Range, vCur As Variant
Dim isTextFound as Boolean, erroneousCells as String

erroneousCells = "Text is found in the following cells: "

For Each R In Range("A1:A10").SpecialCells(xlCellTypeConstants) 
    vCur = R.Value 
    If IsNumeric(vCur) Then 
        'Do your thing here
    Else
        isTextFound = true
        erroneousCells = erroneousCells + " " + R.Address
    End If 
Next R 

If isTextFound then MsgBox erroneousCells

End Sub

Made from scratch, so don't shoot me if you find any grammatical errors ;)
 
Upvote 0
Hi sorry I was replying to Alan then, must have posted at the same time.

And Martien, sorry, I don't quite understand what you're suggesting? could you explain a little more, sorry
 
Upvote 0
sorry Martien, keep posting at the same time.

Again, I don't want to keep repeating the action. Could I do the action at the end??
 
Upvote 0
Hi

My text is in this sort of format. So in the macro. I check along the rows to see if there is data in, then copy the whole row into another spreadsheet. (that is linked to access). But you can see I need to check down the columns to find any text

1.000 L 1.000 L 1.000 L
2.000 L 2.000 L 2.000 L
3.000 L 3.000 L 3.000 L
text H 4.000 L 4.000 L

Cath
 
Upvote 0
Hehe, it's a bit confusing indeed :biggrin:

I don't quite understand what you mean by repeating the action.
Do you mean you are exporting all the data at once?
If not, you can replace the "A1:A10" with the range where your data is in,
and replace the "Do your thing here" with the steps you are using to export your data.

Hmm, I just read your last post, I think I can write a short function for that. Hang on a little ;)
 
Upvote 0

Forum statistics

Threads
1,207,423
Messages
6,078,443
Members
446,339
Latest member
keogata

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