Adapt some VBA

j4ymf

Well-known Member
Joined
Apr 28, 2003
Messages
523
hello I have found this code

how do I change the code to only change the selected cells to turn white
Cells.Interior.ColorIndex = 0

Cells(A12:AE39).Interior.ColorIndex = 0
I only want it to work on A12:AE39



Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
Application.ScreenUpdating = False
'Clear all cell colours
Cells.Interior.ColorIndex = 0
With Target
'Row and column highlightingfor the active cell
.EntireRow.Interior.ColorIndex = 19
.EntireColumn.Interior.ColorIndex = 19
End With
Application.ScreenUpdating = True
End Sub

Thank Jay
 

mohadin

Active Member
Joined
Mar 22, 2015
Messages
361
Office Version
2013
Platform
Windows
How about
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
Application.ScreenUpdating = False
'Clear all cell colours
Cells.Interior.ColorIndex = 0
With Target
'Row and column highlightingfor the active cell
.Interior.ColorIndex = 19
End With
Application.ScreenUpdating = True
End Sub
 

mohadin

Active Member
Joined
Mar 22, 2015
Messages
361
Office Version
2013
Platform
Windows
Or may be
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Cells.Count > 1 Then Exit Sub
    Application.ScreenUpdating = False
    Cells.Interior.ColorIndex = 0
    If Not Intersect(Target, Range("A12:AE39")) Is Nothing Then
        Target.Interior.ColorIndex = 19
    End If
    Application.ScreenUpdating = True
End Sub
 

j4ymf

Well-known Member
Joined
Apr 28, 2003
Messages
523
Good Morning mohadin

thanks for the code

it works good but what im after is for the code to only change the background colour to white
Cells.Interior.ColorIndex = 0

my code works more like what im after but it changes the whole sheet and I only want it remove the interior colour between A12:AE39

Your just changes the colour that you have selected, I need it to change the whole row colour
does that make sense
thank you
 

mohadin

Active Member
Joined
Mar 22, 2015
Messages
361
Office Version
2013
Platform
Windows
Like this?
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
[COLOR=#333333][FONT=Verdana]Cells.Interior.ColorIndex = 0[/FONT][/COLOR]
    If Target.Cells.Count > 1 Then Exit Sub
    Application.ScreenUpdating = False
    Cells.Interior.ColorIndex = 0
    If Not Intersect(Target, Range("A12:AE39")) Is Nothing Then
        Target.EntireRow.Interior.ColorIndex = 19
    End If
    Application.ScreenUpdating = True
End Sub
 
Last edited:

j4ymf

Well-known Member
Joined
Apr 28, 2003
Messages
523
hello mohadin

thank you but its still this line what not doing what I need
Cells.Interior.ColorIndex = 0
its chancing the whole sheet white and I only need it to change A12:AE39 white


Cells. range (A12:AE39 Interior.ColorIndex = 0 something like that!!!!!!!
 

mohadin

Active Member
Joined
Mar 22, 2015
Messages
361
Office Version
2013
Platform
Windows
Aha
Code:
[COLOR=#333333]'Cells.Interior.ColorIndex = 0
[/COLOR]Range("A12:AE39").Interior.ColorIndex = 0
 
Last edited:

mohadin

Active Member
Joined
Mar 22, 2015
Messages
361
Office Version
2013
Platform
Windows
Glad I can help
Thank you for feedback
Be happy
 

Forum statistics

Threads
1,078,516
Messages
5,340,875
Members
399,396
Latest member
PBE

Some videos you may like

This Week's Hot Topics

  • Problem with Radio Button's format control
    I am creating an employee evaluation template (a sample is below) Column A is the category Column B, C D, E and F will be ratings (unacceptable...
  • Last Display on userform to a Listbox
    [CODE=vba] lstdisplay.ColumnCount = 15 lstdisplay.RowSource = "A1:O600000" [/CODE] So when i do this it Displays everything on the sheet i am...
  • Rename and move files to a new location
    Dear all, I have an excel file with the following information. The actual file name is at column A but i want to rename it using the following...
  • Help with True/False Formula
    Hello! Am stumped how to fix this formula, in which my result returns 'True', but it should return False. =IF(AG2=True...
  • Clear extra characters from a provided range of cells
    Dear All, I have following code which gives me desired output to remove extra characters from a provided range. But it takes too much time when...
  • Help with Current and highest streaks
    Hi there, I've just joined the forum and this is my first post. I've already spent quite a bit of time searching the net and this forum for a...
Top