ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Dynamic Creation of borders (https://www.excelbanter.com/excel-programming/279615-dynamic-creation-borders.html)

Tyrusst

Dynamic Creation of borders
 
I'm trying to dynamicly create a square ranged border. I take a value
off of the sheet "Param" then try to create a red border on "Magic".
However I keep getting a "Run-tim error '1004': Applicatoin-defined or
object defined error". Is there any other way for me to do this?

Thanks

Adam


Function Build_Grid()

Dim Start As Integer
Start = Worksheets("Param").Range("ODD_INPUT").Value
Worksheets("Magic").Cells.Clear

Worksheets("Magic").Range(Cells(1, 1), Cells(Start,
Start)).BorderAround ColorIndex:=3, Weight:=xlThick


MsgBox "Your Square has been created"




End Function



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/


Tom Ogilvy

Dynamic Creation of borders
 
It should work if the Magic sheet is the activesheet, but I assume it isn't.
The unqualifed Cells(1,1) refers to the activesheet. So you need to use a
with statement

With Worksheets("Magic")
.Range(.Cells(1, 1), .Cells(Start, _
Start)).BorderAround ColorIndex:=3, Weight:=xlThick
End With

Note that the Range and Cells are all preceded by a full stop/period

--
Regards,
Tom Ogilvy

"Tyrusst" wrote in message
...
I'm trying to dynamicly create a square ranged border. I take a value
off of the sheet "Param" then try to create a red border on "Magic".
However I keep getting a "Run-tim error '1004': Applicatoin-defined or
object defined error". Is there any other way for me to do this?

Thanks

Adam


Function Build_Grid()

Dim Start As Integer
Start = Worksheets("Param").Range("ODD_INPUT").Value
Worksheets("Magic").Cells.Clear

Worksheets("Magic").Range(Cells(1, 1), Cells(Start,
Start)).BorderAround ColorIndex:=3, Weight:=xlThick


MsgBox "Your Square has been created"




End Function



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/





All times are GMT +1. The time now is 07:01 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com