Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Test a String to see if it begins with a Number

Hi,

I have a long data file that I am trying to format. There are about
2000 lines in the file, all formatted as text upon import. Many of
the lines are simply lines of text that I am trying to remove, the
goal being to leave behind only the lines that actually contain
numeric data. My thought is to test the first character in each row
to see if it begins with an integer between 1 and 9, inclusive. All
lines meeting this criteria are lines that I want to keep. Any lines
that do not are lines that I want to delete. By looping through the
file, I can fairly quickly clean out all of the excess records. Here
is my code so far:

Dim AcctTest As Variant

'Delete lines that don't contain account balances
Sheets("LYBalances").Range("A1").Select
Do While ActiveCell.Value < ""
AcctTest = (Left(ActiveCell.Value, 1))
AcctTest = AcctTest * 1 'to convert the string into a value
If Not AcctTest < 10 Then
Selection.EntireRow.Delete
ActiveCell.Offset(-1, 0).Select
End If
ActiveCell.Offset(1, 0).Select
Loop

Using this method, I think that the basic question is how to convert
this single character into a value that can be interpreted
mathmatically. I've searched through the newsgroup, but can't find
anything that I seems to help.

Also, I'm sure that there are other ways to tackle this, so other
suggestions are welcome.

TIA,
Randy Eastland
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Test a String to see if it begins with a Number

Hi,

why don't you use Select Case statement


AcctTest = (Left(ActiveCell.Value, 1))
Select Case AcctTest
Case "1" To "9"
'do something
End Select


Haldun


"Randy" , iletide sunu yazdi
om...
Hi,

I have a long data file that I am trying to format. There are about
2000 lines in the file, all formatted as text upon import. Many of
the lines are simply lines of text that I am trying to remove, the
goal being to leave behind only the lines that actually contain
numeric data. My thought is to test the first character in each row
to see if it begins with an integer between 1 and 9, inclusive. All
lines meeting this criteria are lines that I want to keep. Any lines
that do not are lines that I want to delete. By looping through the
file, I can fairly quickly clean out all of the excess records. Here
is my code so far:

Dim AcctTest As Variant

'Delete lines that don't contain account balances
Sheets("LYBalances").Range("A1").Select
Do While ActiveCell.Value < ""
AcctTest = (Left(ActiveCell.Value, 1))
AcctTest = AcctTest * 1 'to convert the string into a value
If Not AcctTest < 10 Then
Selection.EntireRow.Delete
ActiveCell.Offset(-1, 0).Select
End If
ActiveCell.Offset(1, 0).Select
Loop

Using this method, I think that the basic question is how to convert
this single character into a value that can be interpreted
mathmatically. I've searched through the newsgroup, but can't find
anything that I seems to help.

Also, I'm sure that there are other ways to tackle this, so other
suggestions are welcome.

TIA,
Randy Eastland



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Test a String to see if it begins with a Number

Try using the IsNumeric function...

Sub GetNumericRows()
Dim l As Long, lFirst As Long

'find last row
lFirst = Sheets("LYBalances").Range("A65536").End(xlUp).Row

Application.ScreenUpdating = False 'speeds things up

For l = lFirst To 1 Step -1
If Not IsNumeric(Left(Sheets("LYBalances").Cells(l,
1).Formula, 1)) Then _
Sheets("LYBalances").Rows(l).Delete
Next l

End Sub

Cheers,
Dave
-----Original Message-----
Hi,

I have a long data file that I am trying to format.

There are about
2000 lines in the file, all formatted as text upon

import. Many of
the lines are simply lines of text that I am trying to

remove, the
goal being to leave behind only the lines that actually

contain
numeric data. My thought is to test the first character

in each row
to see if it begins with an integer between 1 and 9,

inclusive. All
lines meeting this criteria are lines that I want to

keep. Any lines
that do not are lines that I want to delete. By looping

through the
file, I can fairly quickly clean out all of the excess

records. Here
is my code so far:

Dim AcctTest As Variant

'Delete lines that don't contain account balances
Sheets("LYBalances").Range("A1").Select
Do While ActiveCell.Value < ""
AcctTest = (Left(ActiveCell.Value, 1))
AcctTest = AcctTest * 1 'to convert the string

into a value
If Not AcctTest < 10 Then
Selection.EntireRow.Delete
ActiveCell.Offset(-1, 0).Select
End If
ActiveCell.Offset(1, 0).Select
Loop

Using this method, I think that the basic question is how

to convert
this single character into a value that can be interpreted
mathmatically. I've searched through the newsgroup, but

can't find
anything that I seems to help.

Also, I'm sure that there are other ways to tackle this,

so other
suggestions are welcome.

TIA,
Randy Eastland
.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Test a String to see if it begins with a Number

Look in help at the val function

? val("abcc")
0
? val("123abc")
123

if val(sStr) 0 then
' keep string
else

--
Regards,
Tom Ogilvy

"Randy" wrote in message
om...
Hi,

I have a long data file that I am trying to format. There are about
2000 lines in the file, all formatted as text upon import. Many of
the lines are simply lines of text that I am trying to remove, the
goal being to leave behind only the lines that actually contain
numeric data. My thought is to test the first character in each row
to see if it begins with an integer between 1 and 9, inclusive. All
lines meeting this criteria are lines that I want to keep. Any lines
that do not are lines that I want to delete. By looping through the
file, I can fairly quickly clean out all of the excess records. Here
is my code so far:

Dim AcctTest As Variant

'Delete lines that don't contain account balances
Sheets("LYBalances").Range("A1").Select
Do While ActiveCell.Value < ""
AcctTest = (Left(ActiveCell.Value, 1))
AcctTest = AcctTest * 1 'to convert the string into a value
If Not AcctTest < 10 Then
Selection.EntireRow.Delete
ActiveCell.Offset(-1, 0).Select
End If
ActiveCell.Offset(1, 0).Select
Loop

Using this method, I think that the basic question is how to convert
this single character into a value that can be interpreted
mathmatically. I've searched through the newsgroup, but can't find
anything that I seems to help.

Also, I'm sure that there are other ways to tackle this, so other
suggestions are welcome.

TIA,
Randy Eastland



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Test String LucB Excel Discussion (Misc queries) 2 November 29th 06 02:49 AM
I want to put a bank account number that begins with 00 in Excel. Kbrookfi Excel Worksheet Functions 1 March 9th 06 05:32 AM
How do I type number that begins with a zero to keep zero? Vickie Newton Excel Discussion (Misc queries) 4 September 19th 05 08:28 PM
Pasting a number to Excel that begins with 0 Tom Excel Discussion (Misc queries) 8 September 13th 05 10:50 PM
How do I type in a number that begins with zero? Blindie00 Excel Discussion (Misc queries) 3 December 19th 04 10:05 AM


All times are GMT +1. The time now is 09:52 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"