VBA to replace the last character with a different character

idres

New Member
Joined
Jul 22, 2021
Messages
2
Office Version
  1. 2013
Platform
  1. Windows
أحتاج إلى VBA من شأنه:

1 / ابحث في العمود "A" عن الكلمات التي تحتوي على الحرف الأخير "m".

2 / إن وجد. استبدل الحرف الأخير في كل كلمة بالحرف "s"

لماذا هذا الطلب؟
في لغتي العربية يوجد حرف معقد يتشكل حسب موضع الكلمة. استبدال الجميع لا يعمل ، سوف تفسد الكلمات
إذا كانت هذه الرسالة تأتي في بداية الكلمة أو في وسطها ، فلا خطأ. لكن في نهاية الكلمة ، يكتبها الناس في شكلين ، وهذا يسبب مشكلة عند البحث
 

Attachments

  • 33.jpg
    33.jpg
    47.3 KB · Views: 19

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
يرجى المعذرة عن أي أخطاء في الترجمة ، أنا أستخدم مترجم جوجل.
هل هناك كلمات متعددة في خلية واحدة وإذا كانت هذه الكلمات تنتهي بالحرف "م" ، فأنت ترغب في استبدال "م" بالحرف "ق"؟
 
Upvote 0
Hi @idres, Welcome to MrExcel!

You might be looking for this:
VBA Code:
Sub Idris()
   
    Dim r       As Range
    Dim arr     As Variant
    Dim s       As String
    Dim i       As Long

    With ThisWorkbook.ActiveSheet
        Set r = .Range("A1:A" & .Cells(.Rows.Count, "A").End(xlUp).Row)
        arr = r.Value
        For i = LBound(arr) To UBound(arr)
            If Not IsEmpty(arr(i, 1)) Then
                s = arr(i, 1)
                s = VBA.Join(VBA.Split(s, "m "), "s ")
                s = VBA.Join(VBA.Split(s, "m" & vbLf), "s" & vbLf)
                If Right$(s, 1) = "m" Then
                    s = Left$(s, Len(s) - 1) & "s"
                End If
                arr(i, 1) = s
            End If
        Next i
        r.Value = arr
    End With
End Sub
 
Upvote 0
Solution
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: VBA to replace the last character with a different character
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
Hi @idres, Welcome to MrExcel!

You might be looking for this:
VBA Code:
Sub Idris()
  
    Dim r       As Range
    Dim arr     As Variant
    Dim s       As String
    Dim i       As Long

    With ThisWorkbook.ActiveSheet
        Set r = .Range("A1:A" & .Cells(.Rows.Count, "A").End(xlUp).Row)
        arr = r.Value
        For i = LBound(arr) To UBound(arr)
            If Not IsEmpty(arr(i, 1)) Then
                s = arr(i, 1)
                s = VBA.Join(VBA.Split(s, "m "), "s ")
                s = VBA.Join(VBA.Split(s, "m" & vbLf), "s" & vbLf)
                If Right$(s, 1) = "m" Then
                    s = Left$(s, Len(s) - 1) & "s"
                End If
                arr(i, 1) = s
            End If
        Next i
        r.Value = arr
    End With
End Sub
Yes, this is . He succeeded. I'm very happy . I was stuck for seven days. Thank you Mr. GWteB Thank you all for the replies you are kind
Regarding cross-posting, I didn't notice, and this is the link VBA to replace the last character with a different character
 
Upvote 0
You are welcome and thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,862
Messages
6,181,457
Members
453,042
Latest member
AbdelrahmanExcel

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top