Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Border Macros

I compiled a macro using the macro recorder to put borders around a
selection of cells.
However, I'm getting the following error when I do two cells.

Run-Time Error '1004': Unable to set the LineStyle property of the
Border class.

I know why this happens as well but not sure what to do to fix it.

Here is the VBA code for it:

Sub borders()
'
' borders Macro
' Macro recorded 24/08/2004 by Steven North
'
' Keyboard Shortcut: Ctrl+Shift+B
'
Selection.borders(xlDiagonalDown).LineStyle = xlNone
Selection.borders(xlDiagonalUp).LineStyle = xlNone
With Selection.borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 48
End With
With Selection.borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlHairline
.ColorIndex = 15
End With
End Sub

Is it possible to do an If statement i.e.

IF ISERROR(With Selection.border(xlInsideVertical)) Then
NEXT WITH
ELSE
CONTINUE
END WITH ????

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Border Macros

How perverse. This seems to work

Sub borders()

With Selection
.borders(xlDiagonalDown).LineStyle = xlNone
.borders(xlDiagonalUp).LineStyle = xlNone
With .borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
If .Columns.Count 1 Then
With .borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 48
End With
End If
With .borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlHairline
.ColorIndex = 15
End With
End With
End Sub




--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Santa-D" wrote in message
ups.com...
I compiled a macro using the macro recorder to put borders around a
selection of cells.
However, I'm getting the following error when I do two cells.

Run-Time Error '1004': Unable to set the LineStyle property of the
Border class.

I know why this happens as well but not sure what to do to fix it.

Here is the VBA code for it:

Sub borders()
'
' borders Macro
' Macro recorded 24/08/2004 by Steven North
'
' Keyboard Shortcut: Ctrl+Shift+B
'
Selection.borders(xlDiagonalDown).LineStyle = xlNone
Selection.borders(xlDiagonalUp).LineStyle = xlNone
With Selection.borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 48
End With
With Selection.borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlHairline
.ColorIndex = 15
End With
End Sub

Is it possible to do an If statement i.e.

IF ISERROR(With Selection.border(xlInsideVertical)) Then
NEXT WITH
ELSE
CONTINUE
END WITH ????



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Border Macros

Found a minor hiccup.

Two cells going up - works
Two cells going right - doesn't work.

Run-Time Error '1004' - Unable to set the linestyle property of the
Border Class.

The line that is highlighted is: .LineStyle = xlContinuous


The section it highlights is:

With .borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlHairline
.ColorIndex = 15
End With
End With
End Sub


I tried changing the section from Count 1 to Count < 1 and going up
two cells in one column which worked but going two cells to the right
didn't.

If .Columns.Count < 1 Then
With .borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 48
End With

Any ideas?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Border Macros

Your change doesn't make any sense at all. I concluded that, notwithstanding
what the macro recorder does, you cannot add an inside vertical on a single
column, hence the test for one than one before adding such. Maybe a similar
test on rows

Sub borders()

With Selection
.borders(xlDiagonalDown).LineStyle = xlNone
.borders(xlDiagonalUp).LineStyle = xlNone
With .borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
If .Columns.Count 1 Then
With .borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 48
End With
End If
If .Rows.Count 1 Then
With .borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlHairline
.ColorIndex = 15
End With
End If
End With
End Sub


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Santa-D" wrote in message
ups.com...
Found a minor hiccup.

Two cells going up - works
Two cells going right - doesn't work.

Run-Time Error '1004' - Unable to set the linestyle property of the
Border Class.

The line that is highlighted is: .LineStyle = xlContinuous


The section it highlights is:

With .borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlHairline
.ColorIndex = 15
End With
End With
End Sub


I tried changing the section from Count 1 to Count < 1 and going up
two cells in one column which worked but going two cells to the right
didn't.

If .Columns.Count < 1 Then
With .borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 48
End With

Any ideas?



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Border Macros

Thanks Bob, that worked a treat. I really appreciate your help, I've
been using that Macro for over four years and it really bugged me when
it came up with that error.


Bob Phillips wrote:
Your change doesn't make any sense at all.


That's because I stayed up late last night and watch the Italy -v-
Australia match in the World Cup last night. It is upsetting to see
Australia loose the way they did when they play very strong. However,
it's fantastic to see Australia get as far as they did. Go Socceroos!



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Border Macros

I came across a bit of an annoyance. When i tried to put borders on a
protected sheet it would report an error. So, I added the following
code.

Sub borders()

Dim x As Variant
Dim wks As Worksheet
Set wks = ActiveSheet

x = ""

If wks.ProtectContents _
Or wks.ProtectDrawingObjects _
Or wks.ProtectScenarios Then

x = True
ActiveWorkbook.Unprotect
ActiveSheet.Unprotect
Else
End If

With Selection
.borders(xlDiagonalDown).LineStyle = xlNone
.borders(xlDiagonalUp).LineStyle = xlNone
With .borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
If .Columns.Count 1 Then
With .borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 48
End With
End If
If .Rows.Count 1 Then
With .borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlHairline
.ColorIndex = 15
End With
End If
End With

If x = True Then
ActiveWorkbook.Protect
ActiveSheet.Protect
Else
End If
End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Border PL Excel Discussion (Misc queries) 3 July 10th 09 05:20 AM
border on last cell of page effects border on beginning cell of ne GaryE Excel Discussion (Misc queries) 0 March 23rd 09 05:47 AM
border Sarah Excel Worksheet Functions 2 December 2nd 07 12:55 AM
Πως μπορώ να συγκρίνω αν 2 κυψέλες έχουν το ίδιο border Stavros Excel Discussion (Misc queries) 0 August 16th 06 01:55 PM
Changing the border of one cell s/n change the border of adjacent gjanssenmn Excel Discussion (Misc queries) 2 October 5th 05 08:35 PM


All times are GMT +1. The time now is 08:02 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright 2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"