どんな関数がセルに入ってるの?
'========================================================'
Sub comment()
On Error Resume Next
Dim comT As String
comT = Selection.Cells.Formula
Selection.AddComment
With Selection
.comment.Text Text:=comT
.comment.Visible = True
End With
Call SizeColor
Call SizeColor2
End Sub
'========================================================'
Sub SizeColor()
If Not Selection.Cells.comment Is Nothing Then
With Selection.Cells.comment.Shape.TextFrame
.AutoSize = True
.Characters.Font.Color = vbBlack
.Characters.Font.Size = 18
End With
End If
End Sub
'========================================================'
Sub SizeColor2()
Dim str1 As String, str2 As String, msg As String, N As String, cnt As Long
str1 = Selection.Cells.Formula
str2 = ","
N = InStr(1, str1, str2)
If Not Selection.Cells.comment Is Nothing Then
With Selection.Cells.comment.Shape.TextFrame
Do While N > 0
cnt = cnt + 1
msg = msg & N & ","
.Characters(N, Len(str2)).Font.Color = rgbRed
N = InStr(N + 1, str1, str2)
Loop
End With
End If
MsgBox cnt
MsgBox msg
End Sub
'========================================================'
何とか出来ました!
Instr関数(インストリング関数)は、文字列の中から指定した文字が何文字目になるのかを返してくれます。カンマが何番目にあるとか、空白が何番目にあるとか数えたい場合など便利です。
上記では、カンマが何個あるのか?と何番目にあるのか?を区別してみました。
何個かを数えるのは単純にcnt(カウント)すればOKです。
何番目かを数えるのはN(文字列)の”,”を指定して数えてもらいます。
カンマを分かりやすく赤色で表示してみました。
以外に難問でした(汗)
VBAを楽しんでやっています。
専門的にVBAをしてる人なら「もっと、こうしたらいいのに!」って有ると思います。僕はVBAをスポーツとして楽しんでる人間なので、インデントのつけ方の悪さやプロシージャの記述の下手さなどはお許しください。
「VBAの記述が見にくい」などは、笑って許して下さい。
今回はこんな感じで、楽しくVBA記載させてもらいました。
ハリネズミを描いてほしいと友人から言われたので、Wordで描きます!
全く自信ない.....。
もう少し勉強します。うまく描けませんでした(反省)
一応、ハリネズミのつもりです!