การทำตัวห้อย, ตัวยก (VBA)

สำหรับการทำตัวห้อย ตัวยกใน Excel จะไม่สามารถจัดการด้วยฟังก์ชั่นได้ กรณีต้องการจัดตัวห้อยตัวยกจำนวนมาก จำเป็นต้องใช้ VBA เข้ามาช่วยในการจัดการครับ

ตัวอย่างต่อไปนี้เป็นการทำตัวห้อย และตัวยก ตามลำดับ ซึ่งเป็นการทำตัวห้อย ตัวยกที่ 3 อักขระหลังสุด โดยให้คลุมพื้นที่ที่ต้องการ แล้วทำการ Run Code ครับ

1. การทำตัวห้อย 3 อักขระสุดท้าย

Sub SubScriptRange()
    Dim r As Range
    For Each r In Selection
        r.Characters(Start:=Len(r) - 3 + 1, Length:=3).Font _
        .Subscript = True
    Next r
End Sub

2. การทำตัวยก 3 อักขระสุดท้าย

Sub SubScriptRange()
    Dim r As Range
    For Each r In Selection
        r.Characters(Start:=Len(r) - 3 + 1, Length:=3).Font _
        .Subscript = True
    Next r
End Sub

Revised: January 28, 2017 at 16:27

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top