We help IT Professionals succeed at work.
Get Started

Create Border Line

Cartillo asked
Last Modified: 2012-05-12
Hi Experts,

I would like to request Experts help. The attached script being used for merge the cells at Week1 to Week5. However, after completion of the macro the last row of each Week sheets without border line.  I have attached the workbook for Experts  perusal. Hope Experts could help me to fix this border line issue.

Sub MergeCells()
Dim c As Range, firstaddress As String, rng1 As Range, rng2 As Range
Dim I As Long, asht As Worksheet

Application.DisplayAlerts = False

Set asht = ActiveSheet
For I = 1 To 5

    Sheets("Week" & I).Activate
    Set rng1 = Sheets("Week" & I).Range("B4:H291")
    With rng1
        Set c = .Find("*")
        If Not c Is Nothing Then
            firstaddress = c.Address
                If c.Offset(1) = "" Then
                    If c.End(xlDown).Row <> Rows.Count Then
                        Set rng2 = Range(c, c.End(xlDown).Offset(-1))
                        Set rng2 = Range(c, Cells(rng1.Cells(rng1.Cells.Count).Row, c.Column))
                    End If
                    With rng2
                        .HorizontalAlignment = xlCenter
                        .VerticalAlignment = xlCenter
                        .WrapText = True
                        .MergeCells = True
                    End With
                End If
                Set c = .FindNext(c)
            'Loop While Not c Is Nothing And c.Address <> firstaddress
            Loop While c.Address <> firstaddress
        End If
    End With
    With rng1
        .Font.Size = 9
        .Font.Bold = True
        With .Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .Color = RGB(100, 100, 100)
        End With
        With .Borders(xlEdgeRight)
            .LineStyle = xlContinuous
            .Color = RGB(100, 100, 100)
        End With
        With .Borders(xlInsideVertical)
            .LineStyle = xlContinuous
            .Color = RGB(100, 100, 100)
        End With
        With .Borders(xlInsideHorizontal)
            .LineStyle = xlContinuous
            .Color = RGB(100, 100, 100)
        End With
    End With
Next I
Application.DisplayAlerts = True

End Sub

Open in new window

Watch Question
Chief Engineer
This problem has been solved!
Unlock 2 Answers and 13 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE