Change color of entire row and column examle

  • Thread starter Thread starter packat
  • Start date Start date
P

packat

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
-------------
 
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
 
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
 
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
 
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
 
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top