Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default How to change active cell border color in Excel 2007

Hi,

I want to change the active cell border colour to red. I foundthe
following code on the net but as a total newbie to VBA in excel I
haven't got a clue where to put it or how to use it. Can somebody
please help.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim v As Variant
v = Array(xlEdgeBottom, xlEdgeTop, xlEdgeRight, xlEdgeLeft)
For Each r In ActiveSheet.UsedRange
With r
For i = 0 To 3
..Borders(v(i)).LineStyle = xlNone
Next
End With
Next

For i = 0 To 3
With ActiveCell.Borders(v(i))
..LineStyle = xlContinuous
..Weight = xlThick
..ColorIndex = 7
End With
Next
End Sub

TIA

Dynamo
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default How to change active cell border color in Excel 2007

Right-click the sheet tab, choose "View Code" and paste the code into the big white area on the right side.
Then on the "File" menu click "Close and Return to Microsoft Excel"

Suggested changes to code:
1. Just below the line "Dim v As Variant" add these two lines...
Dim r
Dim i

2. Change the line...
.ColorIndex = 7

To:

.ColorIndex = 3
--
Jim Cone
Portland, Oregon USA
http://tinyurl.com/ExtrasXL
(utility download - 3 week trial)
..
..
..

<Dynamo
wrote in message
...
Hi,

I want to change the active cell border colour to red. I foundthe
following code on the net but as a total newbie to VBA in excel I
haven't got a clue where to put it or how to use it. Can somebody
please help.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim v As Variant
v = Array(xlEdgeBottom, xlEdgeTop, xlEdgeRight, xlEdgeLeft)
For Each r In ActiveSheet.UsedRange
With r
For i = 0 To 3
..Borders(v(i)).LineStyle = xlNone
Next
End With
Next

For i = 0 To 3
With ActiveCell.Borders(v(i))
..LineStyle = xlContinuous
..Weight = xlThick
..ColorIndex = 7
End With
Next
End Sub

TIA

Dynamo
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default How to change active cell border color in Excel 2007

Ignorance is bliss.

Thanks Jim. I worked out how to do it literally about 5 seconds before
your post. Originally was tring to add it as new macro. Doh.
Anyway, have many sheets within spreadsheet and want do same for all
spreadsheets. Is there a way round to have the activecell changed for
all sheets with just one piece of code. And want happens with merged
cells?

Regards
Paul
On Thu, 25 Nov 2010 09:48:50 -0800, "Jim Cone"
wrote:

Right-click the sheet tab, choose "View Code" and paste the code into the big white area on the right side.
Then on the "File" menu click "Close and Return to Microsoft Excel"

Suggested changes to code:
1. Just below the line "Dim v As Variant" add these two lines...
Dim r
Dim i

2. Change the line...
.ColorIndex = 7

To:

.ColorIndex = 3

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 168
Default How to change active cell border color in Excel 2007

On Nov 25, 11:56*am, Dynamo wrote:
Ignorance is bliss.

Thanks Jim. I worked out how to do it literally about 5 seconds before
your post. *Originally was tring to add it as new macro. Doh.
Anyway, have many sheets within spreadsheet and want do same for all
spreadsheets. Is there a way round to have the activecell changed for
all sheets with just one piece of code. And want happens with merged
cells?

Regards
Paul
On Thu, 25 Nov 2010 09:48:50 -0800, "Jim Cone"



wrote:
Right-click the sheet tab, choose "View Code" and paste the code into the big white area on the right side.
Then on the "File" menu click "Close and Return to Microsoft Excel"


Suggested changes to code:
1. *Just below the line "Dim v As Variant" add these two lines...
* * Dim r
* * Dim i


2. *Change the line...
* *.ColorIndex = 7


* *To: *


* *.ColorIndex = 3- Hide quoted text -


- Show quoted text -


Do you want to change the SAME cell on every sheet
or
when you change sheets and then select another cell change that one
Do you want the changed cells to STAY changed.
When posting it is best to FULLY explain what you want in the FIRST
post.
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 621
Default How to change active cell border color in Excel 2007

Remove the code from sheet module.

Open Thisworkbook module.

Use this event type.................

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As
Range)

your code here

End Sub

As far as merged cells go......have you tested your code on them??

My opinion of merged cells is that they should never have been invented due to
the numerous problems they cause.


Gord Dibben MS Excel MVP

On Thu, 25 Nov 2010 17:56:43 +0000, Dynamo wrote:

Ignorance is bliss.

Thanks Jim. I worked out how to do it literally about 5 seconds before
your post. Originally was tring to add it as new macro. Doh.
Anyway, have many sheets within spreadsheet and want do same for all
spreadsheets. Is there a way round to have the activecell changed for
all sheets with just one piece of code. And want happens with merged
cells?

Regards
Paul
On Thu, 25 Nov 2010 09:48:50 -0800, "Jim Cone"
wrote:

Right-click the sheet tab, choose "View Code" and paste the code into the big white area on the right side.
Then on the "File" menu click "Close and Return to Microsoft Excel"

Suggested changes to code:
1. Just below the line "Dim v As Variant" add these two lines...
Dim r
Dim i

2. Change the line...
.ColorIndex = 7

To:

.ColorIndex = 3



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default How to change active cell border color in Excel 2007

Yes, you can accomplish that with one piece of code.
The code needs to be modified, the old code removed and the modified code placed in a different location.
The modified code will work the same on merged cells as it does now.
'---
The modified code is below. It must be placed in the "ThisWorkbook" module.
It is found in the VBA project window (top left) under the name of your workbook.
'---
Jim Cone
http://www.contextures.com/excel-sort-addin.html
(30+ ways to sort)

'---
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Dim v As Variant
Dim r As Range
Dim i As Long

v = Array(xlEdgeBottom, xlEdgeTop, xlEdgeRight, xlEdgeLeft)
For Each r In Sh.UsedRange.Cells
With r
For i = 0 To 3
..Borders(v(i)).LineStyle = xlNone
Next
End With
Next

For i = 0 To 3
With Target(1).Borders(v(i))
..LineStyle = xlContinuous
..Weight = xlThick
..ColorIndex = 3
End With
Next
End Sub
'---

..
..

<Dynamo wrote in message
...
Ignorance is bliss.

Thanks Jim. I worked out how to do it literally about 5 seconds before
your post. Originally was tring to add it as new macro. Doh.
Anyway, have many sheets within spreadsheet and want do same for all
spreadsheets. Is there a way round to have the activecell changed for
all sheets with just one piece of code. And want happens with merged
cells?
Regards
Paul

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default How to change active cell border color in Excel 2007

Jim,
Thank you so much for your patience. Your instructions were so easy to
understand and code works fine. Took me a while to find out where the
vba window was cos didnt have the developers ribbon turned on in excel
options. Anyway, one last question for you now that I can see what the
code actually does. Is it possible to do the same for selected cells
rather than active cells? Problem with existing code is that if more
than one cell is selected only the first cell has the border colour
changed.
Thanks once again.
Paul

On Thu, 25 Nov 2010 10:44:23 -0800, "Jim Cone"
wrote:

Yes, you can accomplish that with one piece of code.
The code needs to be modified, the old code removed and the modified code placed in a different location.
The modified code will work the same on merged cells as it does now.
'---
The modified code is below. It must be placed in the "ThisWorkbook" module.
It is found in the VBA project window (top left) under the name of your workbook.
'---
Jim Cone
http://www.contextures.com/excel-sort-addin.html
(30+ ways to sort)

'---
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Dim v As Variant
Dim r As Range
Dim i As Long

v = Array(xlEdgeBottom, xlEdgeTop, xlEdgeRight, xlEdgeLeft)
For Each r In Sh.UsedRange.Cells
With r
For i = 0 To 3
.Borders(v(i)).LineStyle = xlNone
Next
End With
Next

For i = 0 To 3
With Target(1).Borders(v(i))
.LineStyle = xlContinuous
.Weight = xlThick
.ColorIndex = 3
End With
Next
End Sub
'---

.
.

<Dynamo wrote in message
.. .
Ignorance is bliss.

Thanks Jim. I worked out how to do it literally about 5 seconds before
your post. Originally was tring to add it as new macro. Doh.
Anyway, have many sheets within spreadsheet and want do same for all
spreadsheets. Is there a way round to have the activecell changed for
all sheets with just one piece of code. And want happens with merged
cells?
Regards
Paul

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default How to change active cell border color in Excel 2007

Hi Don,

Appreciate your comment about fully explaining in first post but as a
total newbie, until I could see what the initilal code actually did, I
was unable to assess wether it suited my needs. But I am a fast
learner. Jim Clone has answered my questions but I appreciate your
input.

Paul

On Thu, 25 Nov 2010 10:36:27 -0800 (PST), Don Guillett Excel MVP
wrote:

On Nov 25, 11:56*am, Dynamo wrote:
Ignorance is bliss.

Thanks Jim. I worked out how to do it literally about 5 seconds before
your post. *Originally was tring to add it as new macro. Doh.
Anyway, have many sheets within spreadsheet and want do same for all
spreadsheets. Is there a way round to have the activecell changed for
all sheets with just one piece of code. And want happens with merged
cells?

Regards
Paul
On Thu, 25 Nov 2010 09:48:50 -0800, "Jim Cone"



wrote:
Right-click the sheet tab, choose "View Code" and paste the code into the big white area on the right side.
Then on the "File" menu click "Close and Return to Microsoft Excel"


Suggested changes to code:
1. *Just below the line "Dim v As Variant" add these two lines...
* * Dim r
* * Dim i


2. *Change the line...
* *.ColorIndex = 7


* *To: *


* *.ColorIndex = 3- Hide quoted text -


- Show quoted text -


Do you want to change the SAME cell on every sheet
or
when you change sheets and then select another cell change that one
Do you want the changed cells to STAY changed.
When posting it is best to FULLY explain what you want in the FIRST
post.

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default How to change active cell border color in Excel 2007

Hi Gord,

Thanks for your input. Much appreciated. Have written another message
in response to Jim Clones input which was much the same as yours and
works fine but now I see what it does it is not exactly what I want.
Needs some fine tuning. If Jim doent come up with an answer then
perhaps you can.

Paul

On Thu, 25 Nov 2010 10:37:20 -0800, Gord Dibben
wrote:

Remove the code from sheet module.

Open Thisworkbook module.

Use this event type.................

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As
Range)

your code here

End Sub

As far as merged cells go......have you tested your code on them??

My opinion of merged cells is that they should never have been invented due to
the numerous problems they cause.


Gord Dibben MS Excel MVP

On Thu, 25 Nov 2010 17:56:43 +0000, Dynamo wrote:

Ignorance is bliss.

Thanks Jim. I worked out how to do it literally about 5 seconds before
your post. Originally was tring to add it as new macro. Doh.
Anyway, have many sheets within spreadsheet and want do same for all
spreadsheets. Is there a way round to have the activecell changed for
all sheets with just one piece of code. And want happens with merged
cells?

Regards
Paul
On Thu, 25 Nov 2010 09:48:50 -0800, "Jim Cone"
wrote:

Right-click the sheet tab, choose "View Code" and paste the code into the big white area on the right side.
Then on the "File" menu click "Close and Return to Microsoft Excel"

Suggested changes to code:
1. Just below the line "Dim v As Variant" add these two lines...
Dim r
Dim i

2. Change the line...
.ColorIndex = 7

To:

.ColorIndex = 3

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default How to change active cell border color in Excel 2007

"Is it possible to do the same for selected cells rather than active cells?

Just remove "(1)" in this line...
With Target(1).Borders(v(i))
'---
Also, the entire code set can be simplified by replacing it with...
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Sh.UsedRange.Borders.LineStyle = xlLineStyleNone
Target.Cells.BorderAround xlContinuous, xlThick, 3
End Sub
'---
The above code, however, may not be reliable in xl2010 as in the Tech Preview release of xl2010
the BorderAround method was often ignored
--
Jim Cone

..
..

<Dynamo wrote in message
...
Jim,
Thank you so much for your patience. Your instructions were so easy to
understand and code works fine. Took me a while to find out where the
vba window was cos didnt have the developers ribbon turned on in excel
options. Anyway, one last question for you now that I can see what the
code actually does. Is it possible to do the same for selected cells
rather than active cells? Problem with existing code is that if more
than one cell is selected only the first cell has the border colour
changed.
Thanks once again.
Paul



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default How to change active cell border color in Excel 2007

Jim,
Once again many thanks. Both codes worked fine. Just got my head round
2007 let alone xl2010 so who cares if it aint reliable in xl2010.

Now to get round next problem of changing the cell colour using the
same method. Think I can work that one out for myself now that you've
given me the basic idea.
Cant thank you enough.
Regards
Paul

On Thu, 25 Nov 2010 12:14:56 -0800, "Jim Cone"
wrote:

"Is it possible to do the same for selected cells rather than active cells?

Just remove "(1)" in this line...
With Target(1).Borders(v(i))
'---
Also, the entire code set can be simplified by replacing it with...
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Sh.UsedRange.Borders.LineStyle = xlLineStyleNone
Target.Cells.BorderAround xlContinuous, xlThick, 3
End Sub
'---
The above code, however, may not be reliable in xl2010 as in the Tech Preview release of xl2010
the BorderAround method was often ignored

  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to change active cell border color in Excel 2007

On Thu, 25 Nov 2010 10:36:27 -0800 (PST), Don Guillett Excel MVP
wrote:

On Nov 25, 11:56*am, Dynamo wrote:
Ignorance is bliss.

Thanks Jim. I worked out how to do it literally about 5 seconds before
your post. *Originally was tring to add it as new macro. Doh.
Anyway, have many sheets within spreadsheet and want do same for all
spreadsheets. Is there a way round to have the activecell changed for
all sheets with just one piece of code. And want happens with merged
cells?

Regards
Paul
On Thu, 25 Nov 2010 09:48:50 -0800, "Jim Cone"



wrote:
Right-click the sheet tab, choose "View Code" and paste the code into the big white area on the right side.
Then on the "File" menu click "Close and Return to Microsoft Excel"


Suggested changes to code:
1. *Just below the line "Dim v As Variant" add these two lines...
* * Dim r
* * Dim i


2. *Change the line...
* *.ColorIndex = 7


* *To: *


* *.ColorIndex = 3- Hide quoted text -


- Show quoted text -


Do you want to change the SAME cell on every sheet
or
when you change sheets and then select another cell change that one
Do you want the changed cells to STAY changed.
When posting it is best to FULLY explain what you want in the FIRST
post.



You obviously have reading comprehension issues.
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
Active Cell Border Color Linda Oshkosh WI Excel Worksheet Functions 2 May 29th 10 09:12 PM
active cell border color mike d Excel Discussion (Misc queries) 1 May 16th 08 10:35 AM
Change cell selection border color in excel to stand out more? Jeanne Excel Worksheet Functions 3 April 11th 08 09:22 PM
On a Mac how do I change the border colour of the active cell? Lino Excel Discussion (Misc queries) 2 May 23rd 06 01:36 PM
How to change the default Border, Font Color, and Cell Color Elijah Excel Discussion (Misc queries) 3 November 2nd 05 11:52 PM


All times are GMT +1. The time now is 09:28 PM.

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"