Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Declaring an array variable
Here is another way to structure your code...
Sub AddBorders() Dim V As Variant For Each V In Array(xlEdgeLeft, xlEdgeRight, xlEdgeTop, xlEdgeBottom, _ xlInsideVertical, xlInsideHorizontal) With Selection.Borders(V) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = 0 End With Next End Sub -- Rick (MVP - Excel) "fisch4bill" wrote in message ... I'm working on a project that involves putting borders around several ranges of cells. I've been able to condense the code to the following, but, I think I've seen a one-liner method of declaring and assigning values to an array variable. Option Explicit Sub BorderApplication() Dim X(5) As XlBordersIndex Dim N As Integer X(0) = (xlEdgeLeft) X(1) = (xlEdgeRight) X(2) = (xlEdgeTop) X(3) = (xlEdgeBottom) X(4) = (xlInsideVertical) X(5) = (xlInsideHorizontal) For N = 0 To 5 With Selection.Borders(X(N)) .LineStyle = xlContinuous .ColorIndex = 0 .Weight = xlThin End With Next N End Sub Is there a way to assign all these values to X(N) in a single line or am I confusing this with another language? And on another tack, is there a different way to loop through the values? Even doing it this way will streamline my code, but, I'm looking for even more simplicity if it's available. Thanks in advance, Bill |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Declaring an array variable
Thanks to both OssieMac and Rick. This is exactly what I was looking for.
Bill "Rick Rothstein" wrote: Here is another way to structure your code... Sub AddBorders() Dim V As Variant For Each V In Array(xlEdgeLeft, xlEdgeRight, xlEdgeTop, xlEdgeBottom, _ xlInsideVertical, xlInsideHorizontal) With Selection.Borders(V) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = 0 End With Next End Sub -- Rick (MVP - Excel) "fisch4bill" wrote in message ... I'm working on a project that involves putting borders around several ranges of cells. I've been able to condense the code to the following, but, I think I've seen a one-liner method of declaring and assigning values to an array variable. Option Explicit Sub BorderApplication() Dim X(5) As XlBordersIndex Dim N As Integer X(0) = (xlEdgeLeft) X(1) = (xlEdgeRight) X(2) = (xlEdgeTop) X(3) = (xlEdgeBottom) X(4) = (xlInsideVertical) X(5) = (xlInsideHorizontal) For N = 0 To 5 With Selection.Borders(X(N)) .LineStyle = xlContinuous .ColorIndex = 0 .Weight = xlThin End With Next N End Sub Is there a way to assign all these values to X(N) in a single line or am I confusing this with another language? And on another tack, is there a different way to loop through the values? Even doing it this way will streamline my code, but, I'm looking for even more simplicity if it's available. Thanks in advance, Bill . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Declaring an array variable | Excel Programming | |||
Declaring a tab name as a variable | Excel Programming | |||
Help declaring array limit with variable? | Excel Programming | |||
Declaring variable as a dynamic array? | Excel Programming | |||
Declaring a variable? | Excel Programming |