PC Review


Reply
Thread Tools Rate Thread

Condensing Format Code

 
 
baconcow
Guest
Posts: n/a
 
      29th May 2008
I wanted to shorten the macro-made format code:

I used this hoping to shorten the amount of code needed to format the cells,
but it gives me a type mismatch. I am also hoping to use Arrays with text in
them for many other areas of my code. Is this possible?

Set format_range = Worksheets("Surface").Range("A5",
cell_range.Offset(cell_count1 - 1, 10))
format_borders = Array("xlEdgeLeft", "xlEdgeTop", "xlEdgeBottom",
"xlEdgeRight")

Dim c As Long

For c = 0 To 3
With format_range.Borders(format_borders(c))
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.TintAndShade = 0
.Weight = xlMedium
End With
Next c


What am I doing wrong? Thanks.
 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      29th May 2008
the following consnts are number, you made them strings". Remove the double
quotes.

format_borders = Array(xlEdgeLeft, xlEdgeTop, xlEdgeBottom, xlEdgeRight)


"baconcow" wrote:

> I wanted to shorten the macro-made format code:
>
> I used this hoping to shorten the amount of code needed to format the cells,
> but it gives me a type mismatch. I am also hoping to use Arrays with text in
> them for many other areas of my code. Is this possible?
>
> Set format_range = Worksheets("Surface").Range("A5",
> cell_range.Offset(cell_count1 - 1, 10))
> format_borders = Array("xlEdgeLeft", "xlEdgeTop", "xlEdgeBottom",
> "xlEdgeRight")
>
> Dim c As Long
>
> For c = 0 To 3
> With format_range.Borders(format_borders(c))
> .LineStyle = xlContinuous
> .ColorIndex = xlAutomatic
> .TintAndShade = 0
> .Weight = xlMedium
> End With
> Next c
>
>
> What am I doing wrong? Thanks.

 
Reply With Quote
 
baconcow
Guest
Posts: n/a
 
      29th May 2008
Thanks, I didn't realized they were numbers. That makes the rest of what I
was doing work!

"Joel" wrote:

> the following consnts are number, you made them strings". Remove the double
> quotes.
>
> format_borders = Array(xlEdgeLeft, xlEdgeTop, xlEdgeBottom, xlEdgeRight)
>
>
> "baconcow" wrote:
>
> > I wanted to shorten the macro-made format code:
> >
> > I used this hoping to shorten the amount of code needed to format the cells,
> > but it gives me a type mismatch. I am also hoping to use Arrays with text in
> > them for many other areas of my code. Is this possible?
> >
> > Set format_range = Worksheets("Surface").Range("A5",
> > cell_range.Offset(cell_count1 - 1, 10))
> > format_borders = Array("xlEdgeLeft", "xlEdgeTop", "xlEdgeBottom",
> > "xlEdgeRight")
> >
> > Dim c As Long
> >
> > For c = 0 To 3
> > With format_range.Borders(format_borders(c))
> > .LineStyle = xlContinuous
> > .ColorIndex = xlAutomatic
> > .TintAndShade = 0
> > .Weight = xlMedium
> > End With
> > Next c
> >
> >
> > What am I doing wrong? Thanks.

 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      29th May 2008
Here is a little know secret.

right click on the VBA window and slect Object Browser. In the top of the
browser there is a search box. Insert xlEdgeLeft and press binoculars.. You
will see all the border constants. Click on each constant and you will see
there value at the bottom of the window Pane.

"baconcow" wrote:

> Thanks, I didn't realized they were numbers. That makes the rest of what I
> was doing work!
>
> "Joel" wrote:
>
> > the following consnts are number, you made them strings". Remove the double
> > quotes.
> >
> > format_borders = Array(xlEdgeLeft, xlEdgeTop, xlEdgeBottom, xlEdgeRight)
> >
> >
> > "baconcow" wrote:
> >
> > > I wanted to shorten the macro-made format code:
> > >
> > > I used this hoping to shorten the amount of code needed to format the cells,
> > > but it gives me a type mismatch. I am also hoping to use Arrays with text in
> > > them for many other areas of my code. Is this possible?
> > >
> > > Set format_range = Worksheets("Surface").Range("A5",
> > > cell_range.Offset(cell_count1 - 1, 10))
> > > format_borders = Array("xlEdgeLeft", "xlEdgeTop", "xlEdgeBottom",
> > > "xlEdgeRight")
> > >
> > > Dim c As Long
> > >
> > > For c = 0 To 3
> > > With format_range.Borders(format_borders(c))
> > > .LineStyle = xlContinuous
> > > .ColorIndex = xlAutomatic
> > > .TintAndShade = 0
> > > .Weight = xlMedium
> > > End With
> > > Next c
> > >
> > >
> > > What am I doing wrong? Thanks.

 
Reply With Quote
 
baconcow
Guest
Posts: n/a
 
      29th May 2008
I've seen those numbers before but I did not know exactly what they
represented in terms of the code. So these are just constants that are built
into VBA? Interesting. Thanks again.

"Joel" wrote:

> Here is a little know secret.
>
> right click on the VBA window and slect Object Browser. In the top of the
> browser there is a search box. Insert xlEdgeLeft and press binoculars.. You
> will see all the border constants. Click on each constant and you will see
> there value at the bottom of the window Pane.
>
> "baconcow" wrote:
>
> > Thanks, I didn't realized they were numbers. That makes the rest of what I
> > was doing work!
> >
> > "Joel" wrote:
> >
> > > the following consnts are number, you made them strings". Remove the double
> > > quotes.
> > >
> > > format_borders = Array(xlEdgeLeft, xlEdgeTop, xlEdgeBottom, xlEdgeRight)
> > >
> > >
> > > "baconcow" wrote:
> > >
> > > > I wanted to shorten the macro-made format code:
> > > >
> > > > I used this hoping to shorten the amount of code needed to format the cells,
> > > > but it gives me a type mismatch. I am also hoping to use Arrays with text in
> > > > them for many other areas of my code. Is this possible?
> > > >
> > > > Set format_range = Worksheets("Surface").Range("A5",
> > > > cell_range.Offset(cell_count1 - 1, 10))
> > > > format_borders = Array("xlEdgeLeft", "xlEdgeTop", "xlEdgeBottom",
> > > > "xlEdgeRight")
> > > >
> > > > Dim c As Long
> > > >
> > > > For c = 0 To 3
> > > > With format_range.Borders(format_borders(c))
> > > > .LineStyle = xlContinuous
> > > > .ColorIndex = xlAutomatic
> > > > .TintAndShade = 0
> > > > .Weight = xlMedium
> > > > End With
> > > > Next c
> > > >
> > > >
> > > > What am I doing wrong? Thanks.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Condensing VBA code Brad Microsoft Excel Misc 3 9th Sep 2009 05:51 PM
Condensing code Brad Microsoft Excel Programming 1 9th Dec 2008 05:27 PM
Condensing Code =?Utf-8?B?c3RldmU=?= Microsoft Excel Programming 1 23rd Aug 2006 08:37 PM
Need help condensing with-end with code excelnut1954 Microsoft Excel Programming 2 1st May 2006 03:49 PM
Trouble Condensing Code Ikaabod Microsoft Excel Programming 3 11th Apr 2006 09:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:28 AM.