Drawing lines to cells with VBA

  • Thread starter Jean-Jerome Doucet via OfficeKB.com
  • Start date
J

Jean-Jerome Doucet via OfficeKB.com

Hi,

I have a couple of rows (which change in numbers of rows when I use another
macro) and I want to put a double line at the bottom of the last row. I used
the recorder to find the beginning of my code and then I modified it for my
specific needs. But it says that the method Range of the object '_Global'
failed. I need my line to be drawn from colomn A to AE. Does anyone see where
is the problem in my code?
Thx!

JJD

Sub Draw_Double_Line()

'Line that find the number of rows.
Let lstRw = Sheets("Formulaire").Range("a65536").End(xlUp).Row

With Worksheets("Formulaire")
Range("A:AE" & lstRw).Borders(xlDiagonalDown).LineStyle = xlNone
Range("A:AE" & lstRw).Borders(xlDiagonalUp).LineStyle = xlNone
Range("A:AE" & lstRw).Borders(xlEdgeLeft).LineStyle = xlNone
Range("A:AE" & lstRw).Borders(xlEdgeTop).LineStyle = xlNone
With Range("A:AE" & lstRw).Borders(xlEdgeBottom)
.LineStyle = xlDouble
.Weight = xlThick
.ColorIndex = 1
End With
Range("A:AE" & lstRw).Borders(xlEdgeRight).LineStyle = xlNone

End With

End Sub
 
T

Tom Ogilvy

Sub Draw_Double_Line()

'Line that find the number of rows.
Let lstRw = Sheets("Formulaire").Range("a65536").End(xlUp).Row
With Worksheets("Formulaire").Cells(lstrw,1).Resize(1,31)

.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
.Borders(xlEdgeLeft).LineStyle = xlNone
.Borders(xlEdgeTop).LineStyle = xlNone
With .Borders(xlEdgeBottom)
.LineStyle = xlDouble
.Weight = xlThick
.ColorIndex = 1
End With
.Borders(xlEdgeRight).LineStyle = xlNone
End With

End Sub

--
Regards,
Tom Ogilvy

Jean-Jerome Doucet via OfficeKB.com said:
Hi,

I have a couple of rows (which change in numbers of rows when I use another
macro) and I want to put a double line at the bottom of the last row. I used
the recorder to find the beginning of my code and then I modified it for my
specific needs. But it says that the method Range of the object '_Global'
failed. I need my line to be drawn from colomn A to AE. Does anyone see where
is the problem in my code?
Thx!

JJD

Sub Draw_Double_Line()

'Line that find the number of rows.
Let lstRw = Sheets("Formulaire").Range("a65536").End(xlUp).Row

With Worksheets("Formulaire")
Range("A:AE" & lstRw).Borders(xlDiagonalDown).LineStyle = xlNone
Range("A:AE" & lstRw).Borders(xlDiagonalUp).LineStyle = xlNone
Range("A:AE" & lstRw).Borders(xlEdgeLeft).LineStyle = xlNone
Range("A:AE" & lstRw).Borders(xlEdgeTop).LineStyle = xlNone
With Range("A:AE" & lstRw).Borders(xlEdgeBottom)
.LineStyle = xlDouble
.Weight = xlThick
.ColorIndex = 1
End With
Range("A:AE" & lstRw).Borders(xlEdgeRight).LineStyle = xlNone

End With

End Sub
 
J

Jean-Jerome Doucet via OfficeKB.com

I found my problem.

Here's the fix :

Range("A" & lstRw & ":AE" & lstRw)

I replaced the range lines with this one.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top