highlighting cell with different color and rows and column with different color

kamranyd

Board Regular
Joined
Apr 24, 2018
Messages
147
Office Version
  1. 2021
Platform
  1. Windows
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Selection.Worksheet.Cells.FormatConditions.Delete
Rows(ActiveCell.Row).FormatConditions.Add xlExpression, , "TRUE"
Rows(ActiveCell.Row).FormatConditions(1).Interior.Color = RGB(255, 128, 128)
Columns(ActiveCell.Column).FormatConditions.Add xlExpression, , "TRUE"
Columns(ActiveCell.Column).FormatConditions(2).Interior.Color = RGB(0, 204, 255)

End Sub

hello everyone. these codes work fine in showing row and columns highlighted when I select any cell. but how to give selected cell different color.
 
I cannot replicate behaviour.
VBA Code:
Private Sub worksheet_SelectionChange(ByVal Target As Range)

Dim RngRow As Range
Dim FndRng As Range
Dim Rng As Range
Dim RowRng As Range

'ActiveSheet.Unprotect

Selection.Worksheet.Cells.FormatConditions.Delete

Set FndRng = Intersect(Target, Range("A2:G1000"))

If Not FndRng Is Nothing Then
Set RngRow = Range("A2:G1000")

ActiveCell.FormatConditions.Add xlExpression, , True
ActiveCell.FormatConditions(1).Interior.Color = RGB(0, 0, 255)

Rows(ActiveCell.Row).FormatConditions.Add xlExpression, , "TRUE"
Rows(ActiveCell.Row).FormatConditions(2).Interior.Color = RGB(255, 0, 0)

End If

Set Rng = Intersect(Target, Range("H2:DW1000"))

If Not Rng Is Nothing Then
Set RowRng = Range("H2:DW1000")
   

ActiveCell.FormatConditions.Add xlExpression, , True
ActiveCell.FormatConditions(1).Interior.Color = RGB(128, 458, 128)
   
Rows(ActiveCell.Row).FormatConditions.Add xlExpression, , "TRUE"
Rows(ActiveCell.Row).FormatConditions(2).Interior.Color = RGB(255, 0, 0)

End If
End Sub

I set conditional formatting for finding duplicate values but these codes remove my conditional formatting, I wan these codes and also need conditional formatting.
 
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
As this is now a totally different question, you will need to start a new thread.
 
Upvote 0
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
ActiveSheet.Unprotect
Application.ScreenUpdating = False
If Application.CutCopyMode = False Then
Application.Calculate
Application.ScreenUpdating = True
End If
ActiveSheet.Protect
End Sub
I want to copy and paste cell values. my worksheet is protected and has selection change event. when I unprotect my sheet copy paste work. but wont work in protected sheet. is there any work around for copy paste work like it work in normal sheet.
 
Upvote 0
That has nothing to do with this thread, so needs a thread of its own.
 
Upvote 0

Forum statistics

Threads
1,215,497
Messages
6,125,157
Members
449,208
Latest member
emmac

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