Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Change color of entire row and column examle


I am reading a book on Excel and VBA programming (for Excel
2000). There is one example in the book that I could not
get to work.
See the code below. This code is Workbook SelectionChange
event, which is supposed to change the color of entire rows
and columns intersecting the selected cell(s).

I am also using Excel2000. Anyone spot any error in this
code?
Thanks,
pac

-------------
Private Sub Worksheet_SelectionChange(ByVal target As Range)
Rows.Interior.ColorIndex = 0
target.EntireColumn.Interior.ColorIndex = 36
target.EntireRow.Interior.ColorIndex = 37
Debug.Print target
End Sub
-------------




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Change color of entire row and column examle

Put the code in the sheet's code module, not the ThisWorkbook
code module.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"packat" wrote in message
news:VFGzd.9118$h.2309@trnddc04...

I am reading a book on Excel and VBA programming (for Excel
2000). There is one example in the book that I could not get
to work.
See the code below. This code is Workbook SelectionChange
event, which is supposed to change the color of entire rows and
columns intersecting the selected cell(s).

I am also using Excel2000. Anyone spot any error in this code?
Thanks,
pac

-------------
Private Sub Worksheet_SelectionChange(ByVal target As Range)
Rows.Interior.ColorIndex = 0
target.EntireColumn.Interior.ColorIndex = 36
target.EntireRow.Interior.ColorIndex = 37
Debug.Print target
End Sub
-------------






  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default Change color of entire row and column examle

Pac
It works for me. Where are you putting this macro? It must be put in
the sheet module of the sheet you want this to happen in.
Do this. Right-click on the sheet tab at the bottom of the screen,
select View Code. This displays the sheet module for that sheet (each sheet
has its own sheet module). Paste your macro into that module. Now go back
to the sheet and it should work. HTH Otto
"packat" wrote in message
news:VFGzd.9118$h.2309@trnddc04...

I am reading a book on Excel and VBA programming (for Excel 2000). There
is one example in the book that I could not get to work.
See the code below. This code is Workbook SelectionChange event, which is
supposed to change the color of entire rows and columns intersecting the
selected cell(s).

I am also using Excel2000. Anyone spot any error in this code?
Thanks,
pac

-------------
Private Sub Worksheet_SelectionChange(ByVal target As Range)
Rows.Interior.ColorIndex = 0
target.EntireColumn.Interior.ColorIndex = 36
target.EntireRow.Interior.ColorIndex = 37
Debug.Print target
End Sub
-------------






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Change color of entire row and column examle

Thanks Cip / Otto fopr a quick response.
I did put the code in the worksheet code module. I also
created a bran new workbook with only one sheet,( sheet1)
and put this code
in the sheet1 code module. Nothing happened.

Somehow, Excel doesn't recognize the SelectionChange event.
I am not sure if I did turn the event off in previous
workbook. But there is nothingelse exists in this new file.

pac






packat wrote:
I am reading a book on Excel and VBA programming (for
Excel
2000). There is one example in the book that I could not
get to work.
See the code below. This code is Workbook SelectionChange
event, which is supposed to change the color of entire
rows
and columns intersecting the selected cell(s).

I am also using Excel2000. Anyone spot any error in this
code?
Thanks,
pac

-------------
Private Sub Worksheet_SelectionChange(ByVal target As
Range)
Rows.Interior.ColorIndex = 0
target.EntireColumn.Interior.ColorIndex = 36
target.EntireRow.Interior.ColorIndex = 37
Debug.Print target
End Sub
-------------



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Change color of entire row and column examle

Ensure that events are enabled. In VBA, open the Immediate
Windows (CTRL+G) and type the following and press Enter:

Application.EnableEvents = True


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"packat" wrote in message
news:UfHzd.4203$Y57.1975@trnddc08...
Thanks Cip / Otto fopr a quick response.
I did put the code in the worksheet code module. I also
created a bran new workbook with only one sheet,( sheet1) and
put this code
in the sheet1 code module. Nothing happened.

Somehow, Excel doesn't recognize the SelectionChange event. I
am not sure if I did turn the event off in previous workbook.
But there is nothingelse exists in this new file.

pac






packat wrote:
I am reading a book on Excel and VBA programming (for Excel
2000). There is one example in the book that I could not
get to work.
See the code below. This code is Workbook SelectionChange
event, which is supposed to change the color of entire rows
and columns intersecting the selected cell(s).

I am also using Excel2000. Anyone spot any error in this
code?
Thanks,
pac

-------------
Private Sub Worksheet_SelectionChange(ByVal target As Range)
Rows.Interior.ColorIndex = 0
target.EntireColumn.Interior.ColorIndex = 36
target.EntireRow.Interior.ColorIndex = 37
Debug.Print target
End Sub
-------------







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Change color of entire row and column examle

Chip,
I tried what you suggested, but there is no change.

I also tried adding this code to another workbook that has a
working Worksheet Change event.
And it does not work there either.
Thanks,
pac



Chip Pearson wrote:
Ensure that events are enabled. In VBA, open the
Immediate
Windows (CTRL+G) and type the following and press Enter:

Application.EnableEvents = True



"packat" wrote in message
news:UfHzd.4203$Y57.1975@trnddc08...
Thanks Cip / Otto fopr a quick response.
I did put the code in the worksheet code module. I also
created a bran new workbook with only one sheet,( sheet1)
and
put this code
in the sheet1 code module. Nothing happened.

Somehow, Excel doesn't recognize the SelectionChange
event. I
am not sure if I did turn the event off in previous
workbook.
But there is nothingelse exists in this new file.

pac






packat wrote:
I am reading a book on Excel and VBA programming (for
Excel
2000). There is one example in the book that I could
not
get to work.
See the code below. This code is Workbook
SelectionChange
event, which is supposed to change the color of entire
rows
and columns intersecting the selected cell(s).

I am also using Excel2000. Anyone spot any error in
this
code?
Thanks,
pac

-------------
Private Sub Worksheet_SelectionChange(ByVal target As
Range)
Rows.Interior.ColorIndex = 0
target.EntireColumn.Interior.ColorIndex = 36
target.EntireRow.Interior.ColorIndex = 37
Debug.Print target
End Sub
-------------



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Change color of entire row and column examle

I am not sure what I did, but the example works perfectly
now.
Thanks for all the helps. I can now continue with my study.
pac

packat wrote:
I am reading a book on Excel and VBA programming (for
Excel
2000). There is one example in the book that I could not
get to work.
See the code below. This code is Workbook SelectionChange
event, which is supposed to change the color of entire
rows
and columns intersecting the selected cell(s).

I am also using Excel2000. Anyone spot any error in this
code?
Thanks,
pac

-------------
Private Sub Worksheet_SelectionChange(ByVal target As
Range)
Rows.Interior.ColorIndex = 0
target.EntireColumn.Interior.ColorIndex = 36
target.EntireRow.Interior.ColorIndex = 37
Debug.Print target
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
change color of entire row by use conditional format Montu Excel Worksheet Functions 2 November 15th 07 10:02 AM
change first letter of a word for an entire column lori12844 Excel Discussion (Misc queries) 5 May 30th 07 06:06 AM
Change font color across entire row Mac Excel Discussion (Misc queries) 4 November 17th 06 04:13 AM
If data in one column, take date, add 2 days, and turn the entire column a color... [email protected] Excel Discussion (Misc queries) 6 August 24th 06 03:58 AM
Color Entire Rows depending on Text in Column A Rashid Khan Excel Programming 3 December 23rd 04 05:06 PM


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

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

About Us

"It's about Microsoft Excel"