[ 初めての方へ | 一覧(最新更新順) | 全文検索 | 過去ログ ]
『化学式の数値を一括で下付き 新しい条件』(たなか)
お世話になります。
少し前、[[20181024103531]] 『化学式の数値を一括で下付きにしたいです。』でお世話になりました。
seiyaさんに作っていただいたマクロを使わせていただいています。
「pH」の後ろの数値は小さくしないとリクエストし、その通りになっていて感動している次第です。
が、新たに " ) " (半角カッコトジル)の後ろの数字も小さくしてはいけないということに気づきました。
この新しい条件はどのように加えたらよいのでしょうか。
(↓元のマクロです)
Sub test() Dim r As Range, m As Object With CreateObject("VBScript.RegExp") .Global = True .Pattern = "([A-Za-z]+|\))\d+" For Each r In Range("a1", Range("a" & Rows.Count).End(xlUp)) For Each m In .Execute(r.Value) If m.submatches(0) <> "pH" Then r.Characters(m.firstindex + Len(m.submatches(0)) + 1, _ m.Length - Len(m.submatches(0))).Font.Subscript = True End If Next Next End With End Sub
単純に下記を追加では、全然ダメなんですかねぇ…?
If m.submatches(0) <> ")" Then r.Characters(m.firstindex + Len(m.submatches(0)) + 1, _ m.Length - Len(m.submatches(0))).Font.Subscript = True End If
よろしくお願いします。
< 使用 Excel:Excel2013、使用 OS:Windows7 >
Sub 化学式作成_seiya式_改良版() Dim r As Range, m As Object With CreateObject("VBScript.RegExp") .Global = True .Pattern = "([A-Za-z]+|\))\d+" For Each r In Range("A1", Range("a" & Rows.Count).End(xlUp)) For Each m In .Execute(r.Value) If m.submatches(0) <> "pH" And m.submatches(0) <> ")" Then r.Characters(m.firstindex + Len(m.submatches(0)) + 1, _ m.Length - Len(m.submatches(0))).Font.Subscript = True End If Next Next End With End Sub
(名無し) 2018/11/09(金) 19:09
[ 一覧(最新更新順) ]
YukiWiki 1.6.7 Copyright (C) 2000,2001 by Hiroshi Yuki.
Modified by kazu.