Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Find / Replace / * -1

I have a column with numbers. The numbers end in alpha
(A, B, C...). I need to search the column and find 'A'
replace with the number 1 and then multiply by -1. Do
this for all the A's, then search for 'B' and replace
with the number 2 and multiply by -1 and so forth.

Any thoughts on how to do this?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Find / Replace / * -1

If each entry only has one letter, then this may work for you:

Public Sub ReplaceAlphas()
Dim rCell As Range
Dim sRightChar As String
Application.EnableEvents = False
On Error Resume Next
For Each rCell In Columns(1).Cells.SpecialCells( _
xlCellTypeConstants, xlTextValues)
With rCell
sRightChar = Right(.Text, 1)
If sRightChar Like "[A-Z]" Then _
.Value = -(Left(.Text, Len(.Text) - 1) & _
Asc(sRightChar) - 64)
End With
Next rCell
On Error GoTo 0
End Sub





In article ,
wrote:

I have a column with numbers. The numbers end in alpha
(A, B, C...). I need to search the column and find 'A'
replace with the number 1 and then multiply by -1. Do
this for all the A's, then search for 'B' and replace
with the number 2 and multiply by -1 and so forth.

Any thoughts on how to do this?

  #3   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Find / Replace / * -1

Yes each entry only has one letter, and it is at the end
of the data, for example column A has:

0000118800A
0000086780B
0000085170C
0000048567A
0000045830B
0000036000C
0000027140A
0000026170B
0000024280C

I need to find and replace ALL the 'A' with 1 and
multiply by -1, then find and replace ALL the 'B' with 2
and multiply by -1, then find and replace ALL the 'C'
with 3 and multiply by -1. So my results would be

-00001188001
-00000867802
-00000851703
-00000485671
-00000458302
-00000360003
-00000271401
-00000261702
-00000242803


-----Original Message-----
If each entry only has one letter, then this may work

for you:

Public Sub ReplaceAlphas()
Dim rCell As Range
Dim sRightChar As String
Application.EnableEvents = False
On Error Resume Next
For Each rCell In Columns(1).Cells.SpecialCells(

_
xlCellTypeConstants, xlTextValues)
With rCell
sRightChar = Right(.Text, 1)
If sRightChar Like "[A-Z]" Then _
.Value = -(Left(.Text, Len(.Text) -

1) & _
Asc(sRightChar) - 64)
End With
Next rCell
On Error GoTo 0
End Sub





In article ,
wrote:

I have a column with numbers. The numbers end in

alpha
(A, B, C...). I need to search the column and

find 'A'
replace with the number 1 and then multiply by -1. Do
this for all the A's, then search for 'B' and replace
with the number 2 and multiply by -1 and so forth.

Any thoughts on how to do this?

.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Find / Replace / * -1

Then the macro will work. Format column A to retain your leading
zeros.

In article ,
wrote:

Yes each entry only has one letter, and it is at the end
of the data, for example column A has:

0000118800A
0000086780B
0000085170C
0000048567A
0000045830B
0000036000C
0000027140A
0000026170B
0000024280C

I need to find and replace ALL the 'A' with 1 and
multiply by -1, then find and replace ALL the 'B' with 2
and multiply by -1, then find and replace ALL the 'C'
with 3 and multiply by -1. So my results would be

-00001188001
-00000867802
-00000851703
-00000485671
-00000458302
-00000360003
-00000271401
-00000261702
-00000242803


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Find / Replace / * -1

A formula to do all that is
="-"&LEFT(A1,LEN(A1)-1)&(CODE(RIGHT(A1,1))-CODE("A")+1)
The result is treated as a string so you don't need to
format the cells to avoid loss of leading zeroes.

Kevin Beckham

-----Original Message-----
Then the macro will work. Format column A to retain your

leading
zeros.

In article ,
wrote:

Yes each entry only has one letter, and it is at the

end
of the data, for example column A has:

0000118800A
0000086780B
0000085170C
0000048567A
0000045830B
0000036000C
0000027140A
0000026170B
0000024280C

I need to find and replace ALL the 'A' with 1 and
multiply by -1, then find and replace ALL the 'B' with

2
and multiply by -1, then find and replace ALL the 'C'
with 3 and multiply by -1. So my results would be

-00001188001
-00000867802
-00000851703
-00000485671
-00000458302
-00000360003
-00000271401
-00000261702
-00000242803


.

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
Find & Replace: find part cell, replace whole cell katy Excel Worksheet Functions 3 April 3rd 23 01:20 PM
Find and Replace - Replace with Blank Space Studebaker Excel Discussion (Misc queries) 4 April 3rd 23 10:55 AM
where to put results of find operation in find and replace functio DEP Excel Worksheet Functions 5 November 15th 06 07:52 PM
find and replace - replace data in rows to separated by commas msdker Excel Worksheet Functions 1 April 15th 06 01:00 AM
find replace cursor default to find box luffa Excel Discussion (Misc queries) 0 February 3rd 05 12:11 AM


All times are GMT +1. The time now is 06:21 PM.

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"