セルのフォント・塗りつぶし・罫線を設定する:Excel VBA入門 |
スポンサードリンク | |
フォント(Font) | 塗りつぶし(Interior) | 罫線(Borders) |
Sub rei20_01() With Range("A1").Font .Name = "MS明朝" .Bold = True .Color = vbRed .FontStyle = "斜体" .OutlineFont = True .Size = 16 End With End Sub |
Name | フォント名 | MS 明朝、MS ゴシックなど |
Size | フォントサイズ | ポイント単位の数値 |
Color | 色 | vbRed、vbblue など RGB(255, 0, 0)、RGB(0, 255, 0)など |
ColorIndex | 登録番号を指定する | |
Bold | 太字 | True/False |
Italic | 斜体 | |
Underline | 下線 | |
Strikethrough | 取消線 | |
FontStyle | フォントのスタイル | 標準、太字、斜体、太字 斜体 |
Superscript | 上付き文字 | True/False |
Subscript | 下付き文字 |
Sub rei20_2() With Range("A1").Characters(Start:=5, Length:=3).Font .Color = vbRed .Size = 16 .Name = "MS ゴシック" .FontStyle = "太字" End With End Sub |
Sub rei20_3() Dim c As Range Dim i As Long For Each c In Selection If c Like "*△*" Or c Like "*○*" Then For i = 1 To Len(c.Value) If Mid(c.Value, i, 1) = "△" Then c.Characters(i, 1).Font.ColorIndex = 3 ElseIf Mid(c.Value, i, 1) = "○" Then c.Characters(i, 1).Font.ColorIndex = 4 End If Next i End If Next c End Sub |
Sub rei20_3b() Dim c As Range Dim i As Long Dim F1 As Long, F2 As Long For Each c In Selection c.Font.ColorIndex = xlColorIndexAutomatic For i = 1 To Len(c.Text) Select Case Mid(c.Value, i, 1) Case "「" F1 = i Case "」" F2 = i c.Characters(F1 + 1, F2 - F1 - 1).Font.ColorIndex = 3 End Select Next i Next c End Sub |
Sub rei20_4() With Range("A1:C1").Interior .Color = vbRed End With With Range("A3:C3").Interior .Pattern = xlPatternGray16 .PatternColorIndex = 4 End With End Sub |
Sub rei20_4_2() Dim c As Range Dim myCol As Integer For Each c In Range("A1:A10") If c.Row Mod 2 = 1 Then myCol = 4 Else myCol = 6 End If c.Interior.ColorIndex = myCol Next c End Sub |
Sub rei20_4_3() With Selection.Interior .Pattern = xlPatternChecker .PatternColorIndex = 5 End With End Sub |
Sub rei20_4_4() With Selection.Interior .Pattern = 9 .PatternColorIndex = 5 End With End Sub |
Sub rei20_5() With Range("B2:E5").Borders .Color = vbBlue .LineStyle = xlContinuous .Weight = xlMedium End With End Sub |
Sub rei20_6() With Range("B2:E5").Borders .Color = vbBlue .LineStyle = xlContinuous .Weight = xlMedium End With With Range("B2:E5").Borders(xlInsideHorizontal) .Color = vbGreen .LineStyle = xlContinuous .Weight = xlThin End With With Range("B2:E5").Borders(xlInsideVertical) .Color = vbRed .LineStyle = xlContinuous .Weight = xlThin End With End Sub |
Sub rei20_7() With Range("B2:E5").Borders .LineStyle = xlNone End With End Sub |
罫線の太さ(Weight) | 罫線の種類(LineStyle) | 罫線の位置 | |||
xlHairline | 極細線 | xlContinuous | 実線 | xlEdgeTop | セル範囲の上端 |
xlThin | 細線 | xlDash | 波線 | xlEdgeBottom | セル範囲の下端 |
xlMedium | 中太線 | xlDashDot | 一点鎖線 | xlEdgeLeft | セル範囲の左端 |
xlThick | 太線 | xlDashDotDot | 二点鎖線 | xlEdgeRight | セル範囲の右端 |
xlDot | 点線 | xlInsideHorizontal | セル範囲の内側の水平線 | ||
xlDouble | 二重線 | xlInsideVertical | セル範囲の内側の垂直線 | ||
xlSlantDashDot | 斜め一点鎖線 | xlDiagonalDown | 左上から右下への斜線 | ||
xlLineStyleNone | 線無し | xlDiagonalUp | 左下から右上への斜線 | ||
スポンサードリンク
PageViewCounter
Since2006/2/27