Tweak Code that Changes (Active) Cell Color. Can you help?

Mister H

Well-known Member
Joined
Mar 6, 2002
Messages
1,507
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Excel.Range)
Cells.FormatConditions.Delete
Target.FormatConditions.Add Type:=xlExpression, Formula1:="TRUE"
Target.FormatConditions(1).Interior.ColorIndex = 27
End Sub


Hi:

I use the above code on one of my spreadsheets. What it does is change the color of a cell so that you can see exactly which cell is the active cell. I am having a oproblem when I copy the contents of a cell (right click, copy) and then go to another cell there is nothing there to paste. Also if I do something and then want to cotrrect it the Undo command is not available. I did not write this code so I am not sure on how to fix it. Any ideas?

THANKS,
Mark
Sudbury, Ontario
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
mister.

your macro is a clever way of highlighting a selected cell, but the timing of the macro causes it to fire before you can paste or undo a cell. i don't know how to change this, but the following macro will allow you to copy and paste. you can assign a shortcut key to this and it will be just as effective as Excel's ctrl+c / ctrl+p combo.

while a similar macro for "undo" is feasible, it would be difficult. if this is necessary, i would advise first trying to tinker with the timing on your selection_change macro.

cheers. ben.
Code:
Sub CopyAndPaste()
    
    Dim MyCopyRange as Range, MyPasteRange as Range
    
    Set MyCopyRange = Selection
    Set MyPasteRange = Application.InputBox("Select the cell in which to begin pasting this data", Title:="Paste Range", Type:=8)
    MyCopyRange.Copy (MyPasteRange)
    Cells.FormatConditions.Delete
    ActiveCell.FormatConditions.Add Type:=xlExpression, Formula1:="TRUE"
    ActiveCell.FormatConditions(1).Interior.ColorIndex = 27
End Sub
 
Upvote 0
That's the trouble with using Event procedures. Running a macro clears the Undo stack. And if the code does anything like formatting a cell, the clipboard is cleared too (like it is when you do it manually).

Sorry, I don't know a workaround, other than looking at Excel's built-in thick border and absence of shading to determine which cell is active.
 
Upvote 0
THANK You both... I would prefer not to create anymore buttons on my spreadsheet but if I can't find a workaround I now have the code for the button, thank you..

Andrew, what are you referring to in regards to thick border around the cell? Is this a feature in excel that is adjustable or do you mean just the default border that excel has. If it can be made thicker or a different color that would work great. The problem I have with the default border around the cell is that once I start adding borders to the spreadsheet it becomes very difficult to see the highlighted cell which is why I used the code to changfe the interieor color of the active cell. Any assistance you can provide on the border thing would be great.

THANKS guys...
Mark
 
Upvote 0
By default Excel surrounds the selected range with a thick black border. The active cell retains its shading and the remaing cells in the selection are shaded a darker colour (by superimposing a grey pattern). If you add your own thick border to a cell, Excel changes the colour of its border when the cell is selected (eg to light grey if the added border is black).

Excel also makes the row and column headers of the selection bold.

Personally, I have never had a problem identifying the active cell in this way.
 
Upvote 0

Forum statistics

Threads
1,213,554
Messages
6,114,280
Members
448,562
Latest member
Flashbond

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top