如何格式化合并单元格vba周围的边框

时间:2016-08-14 09:50:36

标签: excel vba excel-vba excel-formula

所以我有一个看起来像下面的合并单元格

enter image description here

以下是我在其周围放置边框的代码:

 Dim c As Range

 For Each c In testing  
      If c.MergeCells Then
           c.Interior.ColorIndex = 19
           c.Borders.LineStyle = xlContinuous
           c.Borders.Weight = xlThick
           c.Borders.Color = vbGreen
       End If
   Next

此代码仅在左上角的单元格周围创建边框(参见图片)。如何确保边框位于整个合并单元格周围?

2 个答案:

答案 0 :(得分:6)

您必须使用引用范围的[I:]: Tracking android devices started [D:]: TrackDeviceTask got: [I:]: Got new device list from adb with 0 devices [D:]: Tracking avd started [D:]: avd watcher *.ini path: 'C:\Users\Jefecito\.android\avd' [D:]: avd watcher android path: 'C:\Users\Jefecito\AppData\Local\Android\ANDROI~1\tools\android.bat' [D:]: avd watcher: got device list from avd with 2 devices

MergeArea

答案 1 :(得分:2)

尝试

With c        'Range of the merged cell
    .BorderAround , Weight:=xlMedium
    .Borders.Color = vbGreen
End With