Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA for excel

Status
Not open for further replies.

aishaaa

Programmer
May 1, 2002
21
0
0
AE

Hi,

i need help on this i have excel sheet its typed in arabic
(right to left)but when i open in my pc i dont have arabic
the word came as squer and the number in opposit side .. i dont care about the word but the number i want it to be in opposit

for example

the current

Name ID
******* - 001-350478-0095 -

i want to be

name ID
******* - 0095-350478-001-

please help me on this ..
 
I wasn't sure if those leading and trailing "-" where meant to be there so here's two solutions. The fist will not work with the "-" at the front and back, the second won't work without them.

Both assume your IDs to start in cell B2 allowing for headers and the Name column. The new data is then put into column C - you can change tha to whatever you wish.

Code:
Option Explicit

Sub NoLeadHyphen()
Dim strFirst As String
Dim strScnd As String
Dim strThrd As String
Dim strInvert As String
Dim iBegin As Integer
Dim iEnd As Integer
Dim c As Range
Dim lRow As Long

    lRow = Range("B65536").End(xlUp).Row
    
    For Each c In Range(Cells(2, 2), Cells(lRow, 2))
        With c
            iBegin = InStr(1, Trim(.Text), "-")
            iEnd = InStrRev(Trim(.Text), "-", Len(Trim(.Text)) - 1)
            strFirst = Left(Trim(.Text), iBegin - 1)
            strScnd = Mid(Trim(.Text), iBegin, iEnd + 1 - iBegin)
            strThrd = Right(Trim(.Text), Len(.Text) - iEnd)
        End With
            strInvert = strThrd & strScnd & strFirst
        c.Offset(0, 1).Value = strInvert
    Next
End Sub



Sub WithLeadHyphen()
Dim strFirst As String
Dim strScnd As String
Dim strThrd As String
Dim strInvert As String
Dim iBegin As Integer
Dim iEnd As Integer
Dim c As Range
Dim lRow As Long

    lRow = Range("B65536").End(xlUp).Row
    
    For Each c In Range(Cells(2, 2), Cells(lRow, 2))
        With c
            iBegin = InStr(2, Trim(.Text), "-")
            iEnd = InStrRev(Trim(.Text), "-", Len(Trim(.Text)) - 1)
            strFirst = Left(Trim(.Text), iBegin)
            strScnd = Mid(Trim(.Text), iBegin + 1, iEnd - iBegin - 1)
            strThrd = Right(Trim(.Text), Len(.Text) - iEnd)
        End With
            strInvert = "-" & Replace(expression:=strThrd & strScnd & strFirst, Find:=" ", Replace:="")
        c.Offset(0, 1).Value = strInvert
    Next
End Sub

Have a nice Weekend!
;-) If a man says something and there are no women there to hear him, is he still wrong?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top