I would like 开发者_开发知识库to find some VBA code that when I left click in a cell on a sheet it will change the cell to yellow. Then lets say I didn't want the cell yellow, I could right click and it would change back. I'm not sure if it's possible or not.
Here's the code that works:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Call ChangeCellColor(Target, 6)
End Sub
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, _
Cancel As Boolean)
Call ChangeCellColor(Target, xlNone)
End Sub
Private Sub ChangeCellColor(Target As Range, CLR As Integer)
Selection.Interior.ColorIndex = CLR
End Sub
here is the code that will change the pattern (this is a striped gray)
With Selection.Interior
.Pattern = xlLightUp
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -4.99893185216834E-02
.PatternTintAndShade = 0
End With
when I dont know the VBA off the top of my head, I go to Excel, View, Macros, Record New Macro..
I then make the changes in Excel that I want, then I go back and turn off the Macro. Lastly, I go and view the macro.. and bam! the code Im looking for is generated there for me.
精彩评论