Find text, Remove it/Replace it then add it to end of current cell orin between (depends) = examples

E

ezduzitez

Hello all,

I would like to be able to find and change cells as noted on the examples below. Your help is greatly appreciated.

If I get help with one example I might be able to figure out the rest.

Ex-1
(Original data) Diameter - Basic: = 2.800 in
(Desired data ) Ø2.800 BASIC

Ex-2
(Original data) Angle Dimension - Basic: = 4.72 deg
(Desired data ) 4.72° BASIC

Ex-3
(Original data) Angle Dimension - Basic: = 51.4 deg 6 places
(Desired data ) 51.4° BASIC - 6 PLACES

Ex-4
(Original data) Linear Dimension - Basic: = .660 in 3 places
(Desired data ) .660 BASIC - 3 PLACES

Thanks you,

EZ
 
C

Claus Busch

Hi,

Am Wed, 1 May 2013 12:32:10 -0700 (PDT) schrieb (e-mail address removed):
Ex-1
(Original data) Diameter - Basic: = 2.800 in
(Desired data ) Ø2.800 BASIC

Ex-2
(Original data) Angle Dimension - Basic: = 4.72 deg
(Desired data ) 4.72° BASIC

Ex-3
(Original data) Angle Dimension - Basic: = 51.4 deg 6 places
(Desired data ) 51.4° BASIC - 6 PLACES

Ex-4
(Original data) Linear Dimension - Basic: = .660 in 3 places
(Desired data ) .660 BASIC - 3 PLACES

your string in A1, then in B1:
=IF(ISNUMBER(FIND("places",A1)),SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"Diameter","Ø")," deg","°")," in",)," - Basic: =",),"Angle Dimension ",),"Linear Dimension ",),"places","PLACES")," "," BASIC - ",1),SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"Diameter","Ø")," deg","°")," in",)," - Basic: =",),"Angle Dimension ",),"Linear Dimension ",),"places","PLACES")&" BASIC")


Regards
Claus Busch
 
C

Claus Busch

Hi,

Am Thu, 2 May 2013 10:13:22 +0200 schrieb Claus Busch:
=IF(ISNUMBER(FIND("places",A1)),SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"Diameter","Ø")," deg","°")," in",)," - Basic: =",),"Angle Dimension ",),"Linear Dimension ",),"places","PLACES")," "," BASIC - ",1),SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"Diameter","Ø")," deg","°")," in",)," - Basic: =",),"Angle Dimension ",),"Linear Dimension ",),"places","PLACES")&" BASIC")

or a little bit shorter:
=UPPER(IF(ISNUMBER(FIND("places",A1)),SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(IF(ISNUMBER(FIND("Diameter",A1)),"Ø"&RIGHT(A1,LEN(A1)-FIND("=",A1)-1),RIGHT(A1,LEN(A1)-FIND("=",A1)-1))," in",)," deg","°")," "," BASIC - ",1),SUBSTITUTE(SUBSTITUTE(IF(ISNUMBER(FIND("Diameter",A1)),"Ø"&RIGHT(A1,LEN(A1)-FIND("=",A1)-1),RIGHT(A1,LEN(A1)-FIND("=",A1)-1))," in",)," deg","°")&" BASIC"))


Regards
Claus Busch
 
C

Claus Busch

Hi,

Am Thu, 2 May 2013 17:37:33 +0200 schrieb Claus Busch:
=UPPER(IF(ISNUMBER(FIND("places",A1)),SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(IF(ISNUMBER(FIND("Diameter",A1)),"Ø"&RIGHT(A1,LEN(A1)-FIND("=",A1)-1),RIGHT(A1,LEN(A1)-FIND("=",A1)-1))," in",)," deg","°")," "," BASIC - ",1),SUBSTITUTE(SUBSTITUTE(IF(ISNUMBER(FIND("Diameter",A1)),"Ø"&RIGHT(A1,LEN(A1)-FIND("=",A1)-1),RIGHT(A1,LEN(A1)-FIND("=",A1)-1))," in",)," deg","°")&" BASIC"))

again a little bit shorter:
=UPPER(IF(ISNUMBER(FIND("places",A1)),SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(IF(ISNUMBER(FIND("Diameter",A1)),"Ø","")&RIGHT(A1,LEN(A1)-FIND("=",A1)-1)," in",)," deg","°")," "," basic - ",1),SUBSTITUTE(SUBSTITUTE(IF(ISNUMBER(FIND("Diameter",A1)),"Ø","")&RIGHT(A1,LEN(A1)-FIND("=",A1)-1)," in",)," deg","°")&" basic"))


Regards
Claus Busch
 
E

ezduzitez

Hi Claus,

I've tried to incorporate this into my module without success. I know enough to get by, but this is too advance for me. I get this "Compile error: Expected: line number or label or statement or end of statement"

Would you mind writing it as if it was one Module for me. I'm missing a basic step and just can't get it :(

Sub Basics()

(needed info)

End Sub

Thanks again,

EZ
 
C

Claus Busch

Hi EZ,

Am Fri, 3 May 2013 07:24:53 -0700 (PDT) schrieb (e-mail address removed):
Would you mind writing it as if it was one Module for me. I'm missing a basic step and just can't get it :(

try:
Sub ChangeText()
Dim LRow As Long
Dim rngC As Range
Dim myStr As String
Dim Start As Integer

LRow = Cells(Rows.Count, 1).End(xlUp).Row
Application.ScreenUpdating = False
For Each rngC In Range("A1:A" & LRow)
myStr = IIf(InStr(rngC, "Diameter"), _
"Ø" & Right(rngC, Len(rngC) - InStr(rngC, "=") - 1), _
Right(rngC, Len(rngC) - InStr(rngC, "=") - 1))
myStr = Replace(Replace(myStr, " in", ""), " deg", "°")
Start = InStr(myStr, " ")
If Start = 0 Then
myStr = myStr & " basic"
Else
myStr = Left(myStr, Start - 1) & " basic - " & _
Right(myStr, Len(myStr) - Start)
End If
myStr = UCase(myStr)
rngC = myStr
Next
Application.ScreenUpdating = True
End Sub


Regards
Claus Busch
 
R

Ron Rosenfeld

Hello all,

I would like to be able to find and change cells as noted on the examples below. Your help is greatly appreciated.

If I get help with one example I might be able to figure out the rest.

Ex-1
(Original data) Diameter - Basic: = 2.800 in
(Desired data ) Ø2.800 BASIC

Ex-2
(Original data) Angle Dimension - Basic: = 4.72 deg
(Desired data ) 4.72° BASIC

Ex-3
(Original data) Angle Dimension - Basic: = 51.4 deg 6 places
(Desired data ) 51.4° BASIC - 6 PLACES

Ex-4
(Original data) Linear Dimension - Basic: = .660 in 3 places
(Desired data ) .660 BASIC - 3 PLACES

Thanks you,

EZ

If I understand your logic correctly, here is a User Defined Function that will accomplish this.

To enter this User Defined Function (UDF), <alt-F11> opens the Visual Basic Editor.
Ensure your project is highlighted in the Project Explorer window.
Then, from the top menu, select Insert/Module and
paste the code below into the window that opens.

To use this User Defined Function (UDF), enter a formula like

=ReArrangeText(A1)

in some cell.

========================================
Option Explicit
Function ReArrangeText(s As String) As String
Dim re As Object, mc As Object
Dim sTemp As String
Set re = CreateObject("vbscript.regexp")
With re
.Global = True
.ignorecase = True
.Pattern = "((?:.*(?=\bDiameter\b))?).*(Basic)\D+?(\d*(?:\.\d+)?\b)(?:\s*(?:(deg)|in)\s*)(\d+\s*places)?"
End With

If re.test(s) = True Then
Set mc = re.Execute(s)
With mc(0)
ReArrangeText = IIf(.submatches(0) <> "", Chr(216), "") & _
UCase(.submatches(2) & _
IIf(.submatches(3) = "deg", Chr(176), "") & " " & .submatches(1) & _
" " & IIf(.submatches(4) <> "", " - ", "") & _
.submatches(4))
End With
End If
End Function
====================================
 
E

ezduzitez

Hi Claus,

You have the right idea, but when I execute it for some reason it fixes allthe cells in the file :(

Hi Ron,

This is my first time using UDF and did not work for me. Don't know what I missed. I copied and pasted the data provided into a module, then I added =ReArrangeText(D8)into a cell, then I called it in a function and it asked me to select a cell or range so when I selected cell D8 nothing happened and when I selected a range from D5 to D12 nothing either :(

I'm providing additional information and hope it will help me explain my issue better. The data that needs fixing is on Column D only and starts at Row 5 and goes down from there.

Original sample data from D5 thru D12
(D5)Ø.938 +.010/-.001 - 7 places
(D6)¨.39 +/-.03
(D7)|⌖|⌀0.030|A|B|
(D8)Diameter - Basic: = 2.800
(D9)Ø.266 +.006/-.001
(D10)Angle Dimension - Basic: = 4.72°
(D11)Angle Dimension - Basic: = 5.2° - 3 Places
(D12)Linear Dimension - Basic: = .660 - 3 Places
==================================================
Desired sample data from D5 thru D12
(D5)Ø.938 +.010/-.001 - 7 places
(D6)¨.39 +/-.03
(D7)|⌖|⌀0.030|A|B|
(D8)Ø2.800 BASIC
(D9)Ø.266 +.006/-.001
(D10)4.72° BASIC
(D11)5.2° BASIC - 3 Places
(D12).660 BASIC - 3 Places

Thanks for your help
 
R

Ron Rosenfeld

This is my first time using UDF and did not work for me. Don't know what I missed.

Well, one thing you missed was providing an example of the data that you would be using.

As far as I can see, NONE of the data in your last example of things that did not work match the format of the original data you supplied.
The UDF was designed to work on the examples you provided. It is unlikely that it would work on non-conforming data.

Here is the original data you gave as examples:

Diameter - Basic: = 2.800 in
Angle Dimension - Basic: = 4.72 deg
Angle Dimension - Basic: = 51.4 deg 6 places
..660 BASIC - 3 PLACES

And here is the data on which the UDF will not work:

Ø.938 +.010/-.001 - 7 places
¨.39 +/-.03
|?|?0.030|A|B|
Diameter - Basic: = 2.800
Ø.266 +.006/-.001
Angle Dimension - Basic: = 4.72°
Angle Dimension - Basic: = 5.2° - 3 Places
Linear Dimension - Basic: = .660 - 3 Place

In particular, note that the unit types in the first set are spelled out as "in" or "deg"; in the second set they are missing or "°". And there are other differences.

Instead of providing multiple incomplete sets of example data, which will require quessing and rewriting in order to finally come up with something that might work, it would be simpler for those responding if you would provide a comprehensive example of the original data and transforms that you require.
 
C

Claus Busch

Hi,

Am Wed, 15 May 2013 14:14:23 -0700 (PDT) schrieb (e-mail address removed):
You have the right idea, but when I execute it for some reason it fixes all the cells in the file :(

then try:

Sub ChangeText()
Dim LRow As Long
Dim rngC As Range
Dim myStr As String
Dim Start As Integer

LRow = Cells(Rows.Count, 1).End(xlUp).Row
Application.ScreenUpdating = False
For Each rngC In Range("A1:A" & LRow)
If InStr(rngC, "=") Then
myStr = IIf(InStr(rngC, "Diameter"), _
"Ø" & Right(rngC, Len(rngC) - InStr(rngC, "=") - 1), _
Right(rngC, Len(rngC) - InStr(rngC, "=") - 1))
myStr = Replace(Replace(myStr, " in", ""), " deg", "°")
Start = InStr(myStr, " ")
If Start = 0 Then
myStr = myStr & " basic"
Else
myStr = Left(myStr, Start - 1) & " basic - " & _
Right(myStr, Len(myStr) - Start)
End If
myStr = UCase(myStr)
rngC = myStr
End If
Next
Application.ScreenUpdating = True
End Sub


Regards
Claus Busch
 
R

Ron Rosenfeld

Hi Claus,

You have the right idea, but when I execute it for some reason it fixes all the cells in the file :(

Hi Ron,

This is my first time using UDF and did not work for me. Don't know what I missed. I copied and pasted the data provided into a module, then I added =ReArrangeText(D8)into a cell, then I called it in a function and it asked me to select a cell or range so when I selected cell D8 nothing happened and when I selected a range from D5 to D12 nothing either :(

I'm providing additional information and hope it will help me explain my issue better. The data that needs fixing is on Column D only and starts at Row 5 and goes down from there.

Original sample data from D5 thru D12
(D5)Ø.938 +.010/-.001 - 7 places
(D6)¨.39 +/-.03
(D7)|?|?0.030|A|B|
(D8)Diameter - Basic: = 2.800
(D9)Ø.266 +.006/-.001
(D10)Angle Dimension - Basic: = 4.72°
(D11)Angle Dimension - Basic: = 5.2° - 3 Places
(D12)Linear Dimension - Basic: = .660 - 3 Places
==================================================
Desired sample data from D5 thru D12
(D5)Ø.938 +.010/-.001 - 7 places
(D6)¨.39 +/-.03
(D7)|?|?0.030|A|B|
(D8)Ø2.800 BASIC
(D9)Ø.266 +.006/-.001
(D10)4.72° BASIC
(D11)5.2° BASIC - 3 Places
(D12).660 BASIC - 3 Places

Thanks for your help

After thinking about it for a bit, here is a routine, based on using regular expressions to examine the different parts of the data, that works on the examples you have provided thus far. It is a macro, rather than a function, so it can change the original cells. However, as written, for debugging purposes it places the results in the adjacent column.

By examining the macro and the comment, you should see near the beginning how you can change rDest to refer to the starting cell of wherever you want to put the results (including the original "D5", once debugged) or in some other cell if you do not want to change what is in column E.

The macro assumes your data starts in D5, and the only data below that in column D is data to be acted upon. It uses similar logic as does the UDF, but has been modified to account for the extra examples you have provided.

To enter this Macro (Sub), <alt-F11> opens the Visual Basic Editor.
Ensure your project is highlighted in the Project Explorer window.
Then, from the top menu, select Insert/Module and
paste the code below into the window that opens.

To use this Macro (Sub), <alt-F8> opens the macro dialog box. Select the macro by name, and <RUN>.

======================================
Option Explicit
Option Compare Text
Sub ReArrangeText()
Dim re As Object, mc As Object
Dim s As String, sIn As String, sPl As String
Dim sVal As String
Dim rSrc As Range, rDest As Range
Dim v As Variant
Dim i As Long

Set rSrc = Range("D5", Cells(Rows.Count, "D").End(xlUp))
Set rDest = Range("E5") 'when working properly, change this to D5

v = rSrc

Set re = CreateObject("vbscript.regexp")
With re
.Global = True
.ignorecase = True
.Pattern = "^.*basic.*?(\xD8?\d*\.?\d+\b\xB0?)\s*(deg|in)?\D*(\d+\s+places)?"
End With

For i = LBound(v) To UBound(v)
s = v(i, 1)
If re.test(s) = True Then
Set mc = re.Execute(s)
sVal = mc(0).submatches(0) 'Value
sIn = mc(0).submatches(1) 'Inches abbrev
sPl = mc(0).submatches(2) 'Places
v(i, 1) = IIf(sPl = "" And Right(sVal, 1) <> Chr(176) And _
(sIn = "" Or sIn = "in"), Chr(216), "") & _
sVal & IIf(sIn = "deg", Chr(176), "") & _
" BASIC " & IIf(sPl <> "", " - ", "") & UCase(sPl)
End If
Next i

rDest.Resize(rowsize:=UBound(v)) = v

End Sub
==================================
 
E

ezduzitez

Thank you Claus and Ron,

This last Macro did the job :)

Your help is greatly appreciated.

Sincerely,

EZ
 
Top