Sub 指定文字列のフォント変更(a_sSearch, a_lColor, a_bBold)Dim f As Font '// FontオブジェクトDim i '// 引数文字列のセルの位置Dim iLen '// 引数文字列の文字数Dim r As Range '// セル範囲の1セル
iLen =Len(a_sSearch)
i =1 '// 選択セル範囲を1セルずつループForEach r In Selection
'// 指定されたセルの文字列から引数文字列を全て検索Do '// セル文字列から引数文字列を検索
i =InStr(i, r.Value, a_sSearch) '// 引数文字列が存在しない場合If(i =0)Then '// 次検索用に検索開始位置を1に初期化
i =1 '// このセルの処理を終了ExitDoEndIf '// 引数文字列部分のFontオブジェクトを取得Set f = r.Characters(i, iLen).Font
'// フォント設定
f.Color = a_lColor '// 文字色
f.Bold = a_bBold '// 太さ '// 次検索用に検索開始位置をずらす
i = i +1LoopNextEndSubSub 指定文字列のフォント変更実行()Call 指定文字列のフォント変更("hoge",RGB(255,0,0),False)EndSub
Sub 色変換()Dim i AsIntegerDim c As Range
ForEach c In Selection '選択された範囲内でFor i =1ToLen(c)With c.Characters(i,1)If.Font.ColorIndex =3Then 'その文字が「赤」のときは.Font.ColorIndex =5 'その文字を「青」にするEndIfEndWithNext i
Next c
EndSub
追記シリーズ
置換で何とかなることのほうが多い。
選択セルに文字を追加
セルの文末に
Sub 選択したセルの文末に文字列追加()
Selection.Value= Evaluate(Selection.Address &"&"" hogehoge""")EndSub
セルの文頭に
Sub 選択したセルの文頭に文字列追加()
Selection.Value= Evaluate("""hogehoge""&"& Selection.Address)EndSub
A computer program is said to learn from experience E with respect to some class of tasks T and performance measure P, if its performance at tasks in T, as measured by P, improves with experience E.
(訳:コンピュータプログラムは、タスクTとパフォーマンス測定Pに関連する経験Eから学習すると言われています。タスクTでパフォーマンスをした場合、パフォーマンス測定Pによって達成度が測定され、経験Eによって改善されていきます。)
import docx
import time
import pandas as pd
print('The strat time is:', time.ctime())
defGetReplaceCSVtoList(path, filename):
data = pd.read_csv(path + filename + '.csv', encoding='shift-jis')
data = data.values.tolist()
return data
defGetWordData(path, filename):
doc = docx.Document(path+filename+'.docx')
return doc
defReplaceMaxLength(line, data):
# cell内でのreplace候補を抽出
temp = []
for i inrange(len(data)):
if data[i][0] in line:
temp.append(data[i])
# cell内のreplace候補のうち、他の変数名の一部である変数を抽出
temp2 = []
for i inrange(len(temp)):
temp1 = temp[0:i]+temp[i+1:len(temp)] # 自分以外のリスト
temp1 = [word[0] for word in temp1] # 自分以外のリストのkeyfor k inrange(len(temp1)):
if temp[i][0] in temp1[k]:
temp2.append(temp[i][0])
# cell内でのreplace候補から、他の変数名の一部である変数を削除
temp3 = [word for word in temp ifnot (word[0] in temp2)]
# 変換for i inrange(len(temp3)):
line = line.replace(temp3[i][0], temp3[i][1])
return line
# --- main ---
path = './(変換テーブルを記載したCSVを含んだフォルダ名)/'
filename = '(ファイル名)'
data = GetReplaceCSVtoList(path, filename)
data = [[word[2], word[3]] for word in data]
path = './(処理前のワードが保存されているフォルダ名)/'
filename = '(処理前のワード名)'
doc = GetWordData(path, filename)
flag = '(処理する表の一つ目のヘッダー)'for tbl in doc.tables:
rowtemp = tbl.rows[0]
if rowtemp.cells[0].text == flag:
for row in tbl.rows:
for cell in row.cells:
cell.text = ReplaceMaxLength(cell.text, data)
doc.save('(保存するワード名).docx')
print('The finish time is:', time.ctime())
for trg inlist(df['column_name2'].sort_values().unique()):
print(
trg
+ 'の最大額:'
+ str(df.loc[df['column_name2']==trg]['column_name1'].max())
+ 'の最小値:'
+ str(df.loc[df['column_name2']==trg]['column_name1'].min(skipna=False))
)