Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 143
Default Test for char in string & separating if present

The data I am working with lists the street name & unit number two different
ways.

Sometimes it looks like this:

MAIN ST#34

and sometimes it looks like this"

MAIN ST #34 (with the unit number in the next column)

What code could I use to test for the existence of '#' in a cell and if it
exists, separate them so the street name stays in the same cell and the unit
number, including the '#' is placed in the next column of the same row?

Thanks for any help or suggestions on this.

Ken Loomis


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Test for char in string & separating if present

Hi
a solutioj without VBA: 'Data - Text to columns' and choose the '#' as
delimiter

--
Regards
Frank Kabel
Frankfurt, Germany

"Ken Loomis" schrieb im Newsbeitrag
...
The data I am working with lists the street name & unit number two

different
ways.

Sometimes it looks like this:

MAIN ST#34

and sometimes it looks like this"

MAIN ST #34 (with the unit number in the next column)

What code could I use to test for the existence of '#' in a cell and

if it
exists, separate them so the street name stays in the same cell and

the unit
number, including the '#' is placed in the next column of the same

row?

Thanks for any help or suggestions on this.

Ken Loomis



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 143
Default Test for char in string & separating if present

Thanks. I did not know about that feature of Excel.

That strips out the text following the '#' and puts it in the next column,
but it wipes out the numbers that are in that column.

Since the unit number is in the street name column at times and in the unit
number column at other times, I need to preserve the unit numbers in the
destination column. It also removes the '#' which I need to have in the
final report.

That is a recordable operation, so I could add that to a macro (which I need
to do anyway) and do the following:

Insert a column
perform the Text to Columns (putting the stripped unit numbers into the
new column)
remove the '#'s from the each cell in the original unit column
for each cell in that new column
concatenate it with a "#" & the next cell in that row
delete the extra column

I could do that, but I was just wondering if there were a solution that
would do that a little more efficiently in VBA since this procedure needs to
be run several times a week.

Thanks,
Ken Loomis

"Frank Kabel" wrote in message
...
Hi
a solutioj without VBA: 'Data - Text to columns' and choose the '#' as
delimiter

--
Regards
Frank Kabel
Frankfurt, Germany

"Ken Loomis" schrieb im Newsbeitrag
...
The data I am working with lists the street name & unit number two

different
ways.

Sometimes it looks like this:

MAIN ST#34

and sometimes it looks like this"

MAIN ST #34 (with the unit number in the next column)

What code could I use to test for the existence of '#' in a cell and

if it
exists, separate them so the street name stays in the same cell and

the unit
number, including the '#' is placed in the next column of the same

row?

Thanks for any help or suggestions on this.

Ken Loomis





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Test for char in string & separating if present

assume the column with the unit numbers correctly separated is column B

Sub Tester1()
Dim iloc As Long, j As Long
Dim rng As Range, cell As Range
Dim cell1 As Range, sStr As String
Set rng = Columns(2).SpecialCells(xlBlanks)
For Each cell In rng
Set cell1 = cell.Offset(0, -1)
sStr = cell1.Value
iloc = InStr(1, sStr, "#", vbTextCompare) - 1
j = Len(sStr)
If iloc 0 Then
cell1.Value = Trim(Left(sStr, iloc))
cell.Value = Trim(Right(sStr, j - iloc))
End If
Next


End Sub


--
Regards,
Tom Ogilvy


"Ken Loomis" wrote in message
...
Thanks. I did not know about that feature of Excel.

That strips out the text following the '#' and puts it in the next column,
but it wipes out the numbers that are in that column.

Since the unit number is in the street name column at times and in the

unit
number column at other times, I need to preserve the unit numbers in the
destination column. It also removes the '#' which I need to have in the
final report.

That is a recordable operation, so I could add that to a macro (which I

need
to do anyway) and do the following:

Insert a column
perform the Text to Columns (putting the stripped unit numbers into

the
new column)
remove the '#'s from the each cell in the original unit column
for each cell in that new column
concatenate it with a "#" & the next cell in that row
delete the extra column

I could do that, but I was just wondering if there were a solution that
would do that a little more efficiently in VBA since this procedure needs

to
be run several times a week.

Thanks,
Ken Loomis

"Frank Kabel" wrote in message
...
Hi
a solutioj without VBA: 'Data - Text to columns' and choose the '#' as
delimiter

--
Regards
Frank Kabel
Frankfurt, Germany

"Ken Loomis" schrieb im Newsbeitrag
...
The data I am working with lists the street name & unit number two

different
ways.

Sometimes it looks like this:

MAIN ST#34

and sometimes it looks like this"

MAIN ST #34 (with the unit number in the next column)

What code could I use to test for the existence of '#' in a cell and

if it
exists, separate them so the street name stays in the same cell and

the unit
number, including the '#' is placed in the next column of the same

row?

Thanks for any help or suggestions on this.

Ken Loomis







  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 143
Default Test for char in string & separating if present

Thanks, Tom. That is slick. And I even am getting to where I can understand
it.

But, now I find that most of those cells that I thought were blank in that
column that is to receive the unit numbers, actual contains a single blank.

Any ideas about a quick way to strip those out with out disturbing the cells
that contain something like "# 123"?

Ken Loomis

"Tom Ogilvy" wrote in message
...
assume the column with the unit numbers correctly separated is column B

Sub Tester1()
Dim iloc As Long, j As Long
Dim rng As Range, cell As Range
Dim cell1 As Range, sStr As String
Set rng = Columns(2).SpecialCells(xlBlanks)
For Each cell In rng
Set cell1 = cell.Offset(0, -1)
sStr = cell1.Value
iloc = InStr(1, sStr, "#", vbTextCompare) - 1
j = Len(sStr)
If iloc 0 Then
cell1.Value = Trim(Left(sStr, iloc))
cell.Value = Trim(Right(sStr, j - iloc))
End If
Next


End Sub


--
Regards,
Tom Ogilvy


"Ken Loomis" wrote in message
...
Thanks. I did not know about that feature of Excel.

That strips out the text following the '#' and puts it in the next
column,
but it wipes out the numbers that are in that column.

Since the unit number is in the street name column at times and in the

unit
number column at other times, I need to preserve the unit numbers in the
destination column. It also removes the '#' which I need to have in the
final report.

That is a recordable operation, so I could add that to a macro (which I

need
to do anyway) and do the following:

Insert a column
perform the Text to Columns (putting the stripped unit numbers into

the
new column)
remove the '#'s from the each cell in the original unit column
for each cell in that new column
concatenate it with a "#" & the next cell in that row
delete the extra column

I could do that, but I was just wondering if there were a solution that
would do that a little more efficiently in VBA since this procedure needs

to
be run several times a week.

Thanks,
Ken Loomis

"Frank Kabel" wrote in message
...
Hi
a solutioj without VBA: 'Data - Text to columns' and choose the '#' as
delimiter

--
Regards
Frank Kabel
Frankfurt, Germany

"Ken Loomis" schrieb im Newsbeitrag
...
The data I am working with lists the street name & unit number two
different
ways.

Sometimes it looks like this:

MAIN ST#34

and sometimes it looks like this"

MAIN ST #34 (with the unit number in the next column)

What code could I use to test for the existence of '#' in a cell and
if it
exists, separate them so the street name stays in the same cell and
the unit
number, including the '#' is placed in the next column of the same
row?

Thanks for any help or suggestions on this.

Ken Loomis











  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Test for char in string & separating if present

Sub Tester1()
Dim iloc As Long, j As Long
Dim rng As Range, cell As Range
Dim cell1 As Range, sStr As String
Columns(2).Replace What:=" ", _
Replacement:="", _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
MatchCase:=False
On Error Resume Next
Set rng = Columns(2).SpecialCells(xlBlanks)
On Error goto 0
if not rng is nothing then
For Each cell In rng
Set cell1 = cell.Offset(0, -1)
sStr = cell1.Value
iloc = InStr(1, sStr, "#", vbTextCompare) - 1
j = Len(sStr)
If iloc 0 Then
cell1.Value = Trim(Left(sStr, iloc))
cell.Value = Trim(Right(sStr, j - iloc))
End If
Next
End if
End Sub

--
Regards,
Tom Ogilvy

"Ken Loomis" wrote in message
...
Thanks, Tom. That is slick. And I even am getting to where I can

understand
it.

But, now I find that most of those cells that I thought were blank in that
column that is to receive the unit numbers, actual contains a single

blank.

Any ideas about a quick way to strip those out with out disturbing the

cells
that contain something like "# 123"?

Ken Loomis

"Tom Ogilvy" wrote in message
...
assume the column with the unit numbers correctly separated is column B

Sub Tester1()
Dim iloc As Long, j As Long
Dim rng As Range, cell As Range
Dim cell1 As Range, sStr As String
Set rng = Columns(2).SpecialCells(xlBlanks)
For Each cell In rng
Set cell1 = cell.Offset(0, -1)
sStr = cell1.Value
iloc = InStr(1, sStr, "#", vbTextCompare) - 1
j = Len(sStr)
If iloc 0 Then
cell1.Value = Trim(Left(sStr, iloc))
cell.Value = Trim(Right(sStr, j - iloc))
End If
Next


End Sub


--
Regards,
Tom Ogilvy


"Ken Loomis" wrote in message
...
Thanks. I did not know about that feature of Excel.

That strips out the text following the '#' and puts it in the next
column,
but it wipes out the numbers that are in that column.

Since the unit number is in the street name column at times and in the

unit
number column at other times, I need to preserve the unit numbers in

the
destination column. It also removes the '#' which I need to have in the
final report.

That is a recordable operation, so I could add that to a macro (which I

need
to do anyway) and do the following:

Insert a column
perform the Text to Columns (putting the stripped unit numbers into

the
new column)
remove the '#'s from the each cell in the original unit column
for each cell in that new column
concatenate it with a "#" & the next cell in that row
delete the extra column

I could do that, but I was just wondering if there were a solution that
would do that a little more efficiently in VBA since this procedure

needs
to
be run several times a week.

Thanks,
Ken Loomis

"Frank Kabel" wrote in message
...
Hi
a solutioj without VBA: 'Data - Text to columns' and choose the '#'

as
delimiter

--
Regards
Frank Kabel
Frankfurt, Germany

"Ken Loomis" schrieb im Newsbeitrag
...
The data I am working with lists the street name & unit number two
different
ways.

Sometimes it looks like this:

MAIN ST#34

and sometimes it looks like this"

MAIN ST #34 (with the unit number in the next column)

What code could I use to test for the existence of '#' in a cell and
if it
exists, separate them so the street name stays in the same cell and
the unit
number, including the '#' is placed in the next column of the same
row?

Thanks for any help or suggestions on this.

Ken Loomis











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
How can I find a value from one cell in a char string in another? tiredazdaddy Excel Worksheet Functions 2 November 20th 08 05:40 PM
How to retrieve certain char within a string? Eric Excel Discussion (Misc queries) 1 July 3rd 07 03:02 AM
How to verify the first char of the string in excel? Eric Excel Discussion (Misc queries) 0 November 30th 06 03:35 AM
string/char CONTAINS function? jim sturtz Excel Worksheet Functions 3 May 31st 06 07:20 PM
Test a cell for a formula present Trebor Retrac Excel Discussion (Misc queries) 1 May 30th 05 05:11 PM


All times are GMT +1. The time now is 07:50 PM.

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

About Us

"It's about Microsoft Excel"