Solved

moving   ANY numeric TERM  to the end of the search term

Posted on 2014-02-26
2
160 Views
Last Modified: 2014-02-27
Excel vba:
Userform
Textbox- search term box

In the code below I'm taking all terms and making me a unique string



What I need:

If i type into the textbox a term like

16oz. HAMMER CLAW

my result looks like this now:
%16oz%HAMMER%CLAW%


I need the term to look like:
%HAMMER%CLAW%16oz%

Another Example:
1/4-20 WASHER 5/8 Hex Head Cap Screw

my result looks like this now:
%1/4-20%WASHER%5/8%Hex%Head%Cap%Screw%

I need the term to look like:
%WASHER%Hex%Head%Cap%Screw%1/4-20%5/8%

Another Example:
1/4in open end wrench

my result looks like this now:
%1/4in%open%end%wrench%


I need the term to look like:
%open%end%wrench%1/4in%

Here is my current code

Dim Nf1 As String
Dim cArrSql As Variant
Dim cD As String
Dim x As Integer
Dim sSpecialChars As String
Dim i As Long
Dim w As String
cD = UserForm2.TextBox33


' strip special characters first NEW way
    sSpecialChars = "!@#$%^&*()_+-={}|[]\:"";'<>?,./~`"
    For i = 1 To Len(sSpecialChars)
        cD = Replace$(cD, Mid$(sSpecialChars, i, 1), " ")
    Next
    cD = cD
' THIS EXCEL TRIM FUNCTION
cD = Application.Trim(cD)
cD = cD
' how many items are in the box ?  build an array
            cArrSql = Split(cD, " ")
            
            
            



If UBound(cArrSql) = 0 Then
 Nf1 = Trim("%" & cArrSql(0) & "%")
Else


                       ' search through the text box requests tokens
                For x = LBound(cArrSql) To UBound(cArrSql)
                    
                        If x = UBound(cArrSql) Then
                                
                                Nf1 = Trim(Nf1 & cArrSql(x) & "%")
                        Else
                                If x = 0 Then
                                 Nf1 = Trim("%" & Nf1 & cArrSql(x) & "%")
                                Else
                                  Nf1 = Trim(Nf1 & cArrSql(x) & "%")
                                End If
                        End If
                Next
End If

Nf1 = Nf1

MsgBox Nf1, vbCritical

Open in new window

0
Comment
Question by:fordraiders
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 52

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39889580
Hi,

pls try

Sub macro()
Dim arrPosition()
Dim arrNewString()
myStringTemp = "%1/4-20%WASHER%5/8%Hex%Head%Cap%Screw%"
myString = Mid(myStringTemp, 2, Len(myStringTemp) - 2)
arrString = Split(myString, "%")
ReDim arrPosition(UBound(arrString))

For Idx = LBound(arrString) To UBound(arrString)
    If arrString(Idx) Like "*#*" Then
        arrPosition(Idx) = True
    Else
        arrPosition(Idx) = False
    End If
Next
ReDim arrNewString(UBound(arrString))
For Idx = LBound(arrString) To UBound(arrString)
    If arrPosition(Idx) = False Then
        arrNewString(Idx1) = arrString(Idx)
        Idx1 = Idx1 + 1
    End If
Next
For Idx = LBound(arrString) To UBound(arrString)
    If arrPosition(Idx) = True Then
        arrNewString(Idx1) = arrString(Idx)
        Idx1 = Idx1 + 1
    End If
Next
myNewString = "%" & Join(arrNewString, "%") & "%"
End Sub

Open in new window

Regards
0
 
LVL 3

Author Closing Comment

by:fordraiders
ID: 39892305
Thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question