highlight active cell Row till "M"

Jagat Pavasia

Board Regular
Joined
Mar 9, 2015
Messages
244
Office Version
  1. 2019
Platform
  1. Windows
I have VBA code to highlight active Row, it is working very well.
but it is highlight whole Row.
I want hightlight in my data entry range.

my data is typed from Row "A" to "M".

please edit VBA code, I am new user in VBA

code Below :

VBA Code:
Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

Static xRow

If xRow <> "" Then
    With Rows(xRow).Interior
        .ColorIndex = xlNone
    End With
End If
pRow = Selection.Row
xRow = pRow
With Rows(pRow).Interior
    .ColorIndex = 34
    .Pattern = xlSolid
End With
End Sub
 

fadee2

Active Member
Joined
Nov 7, 2020
Messages
367
Office Version
  1. 2019
Platform
  1. Windows
try

VBA Code:
Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

Set rng1 = Range(Cells(Selection.Row, 1), Cells(Selection.Row, 7))
Set rng2 = Range(Cells(Selection.Row, 10), Cells(Selection.Row, 12))
Set Rng = Union(rng1, rng2)
Static xRow

If xRow <> "" Then
        Range(Cells(xRow, 1), Cells(xRow, 7)).Interior.ColorIndex = xlNone
        Range(Cells(xRow, 10), Cells(xRow, 12)).Interior.ColorIndex = xlNone
End If
prow = Selection.Row
xRow = prow

With Rng.Interior
    .ColorIndex = 34
    .Pattern = xlSolid
End With
End Sub
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Jagat Pavasia

Board Regular
Joined
Mar 9, 2015
Messages
244
Office Version
  1. 2019
Platform
  1. Windows
try

VBA Code:
Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

Set rng1 = Range(Cells(Selection.Row, 1), Cells(Selection.Row, 7))
Set rng2 = Range(Cells(Selection.Row, 10), Cells(Selection.Row, 12))
Set Rng = Union(rng1, rng2)
Static xRow

If xRow <> "" Then
        Range(Cells(xRow, 1), Cells(xRow, 7)).Interior.ColorIndex = xlNone
        Range(Cells(xRow, 10), Cells(xRow, 12)).Interior.ColorIndex = xlNone
End If
prow = Selection.Row
xRow = prow

With Rng.Interior
    .ColorIndex = 34
    .Pattern = xlSolid
End With
End Sub

try

VBA Code:
Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

Set rng1 = Range(Cells(Selection.Row, 1), Cells(Selection.Row, 7))
Set rng2 = Range(Cells(Selection.Row, 10), Cells(Selection.Row, 12))
Set Rng = Union(rng1, rng2)
Static xRow

If xRow <> "" Then
        Range(Cells(xRow, 1), Cells(xRow, 7)).Interior.ColorIndex = xlNone
        Range(Cells(xRow, 10), Cells(xRow, 12)).Interior.ColorIndex = xlNone
End If
prow = Selection.Row
xRow = prow

With Rng.Interior
    .ColorIndex = 34
    .Pattern = xlSolid
End With
End Sub
YES, THIS CODE IS WORK SOLID AS I WANT.

thank you sir, for whole day helping..

really happy with your help, and you are always happy to help us.
 

fadee2

Active Member
Joined
Nov 7, 2020
Messages
367
Office Version
  1. 2019
Platform
  1. Windows
YES, THIS CODE IS WORK SOLID AS I WANT.

thank you sir, for whole day helping..

really happy with your help, and you are always happy to help us.
You're very welcome....
(y) :):):) .... Happy to help....
 

Jagat Pavasia

Board Regular
Joined
Mar 9, 2015
Messages
244
Office Version
  1. 2019
Platform
  1. Windows
YES, THIS CODE IS WORK SOLID AS I WANT.

thank you sir, for whole day helping..

really happy with your help, and you are always happy to help us.

try

VBA Code:
Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

Set rng1 = Range(Cells(Selection.Row, 1), Cells(Selection.Row, 7))
Set rng2 = Range(Cells(Selection.Row, 10), Cells(Selection.Row, 12))
Set Rng = Union(rng1, rng2)
Static xRow

If xRow <> "" Then
        Range(Cells(xRow, 1), Cells(xRow, 7)).Interior.ColorIndex = xlNone
        Range(Cells(xRow, 10), Cells(xRow, 12)).Interior.ColorIndex = xlNone
End If
prow = Selection.Row
xRow = prow

With Rng.Interior
    .ColorIndex = 34
    .Pattern = xlSolid
End With
End Sub
did it possible to work this VBA code below 6th ROW, because from 1st to 5th ROW has title with background color ?
 

fadee2

Active Member
Joined
Nov 7, 2020
Messages
367
Office Version
  1. 2019
Platform
  1. Windows
VBA Code:
Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Selection.Row >= 6 Then
Set rng1 = Range(Cells(Selection.Row, 1), Cells(Selection.Row, 7))
Set rng2 = Range(Cells(Selection.Row, 10), Cells(Selection.Row, 12))
Set Rng = Union(rng1, rng2)
Static xRow

If xRow <> "" Then
        Range(Cells(xRow, 1), Cells(xRow, 7)).Interior.ColorIndex = xlNone
        Range(Cells(xRow, 10), Cells(xRow, 12)).Interior.ColorIndex = xlNone
End If
prow = Selection.Row
xRow = prow

With Rng.Interior
    .ColorIndex = 34
    .Pattern = xlSolid
End With
Else
If xRow <> "" Then
        Range(Cells(xRow, 1), Cells(xRow, 7)).Interior.ColorIndex = xlNone
        Range(Cells(xRow, 10), Cells(xRow, 12)).Interior.ColorIndex = xlNone
End If
End If
End Sub
 
Solution

Jagat Pavasia

Board Regular
Joined
Mar 9, 2015
Messages
244
Office Version
  1. 2019
Platform
  1. Windows
worked 1
VBA Code:
Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Selection.Row >= 6 Then
Set rng1 = Range(Cells(Selection.Row, 1), Cells(Selection.Row, 7))
Set rng2 = Range(Cells(Selection.Row, 10), Cells(Selection.Row, 12))
Set Rng = Union(rng1, rng2)
Static xRow

If xRow <> "" Then
        Range(Cells(xRow, 1), Cells(xRow, 7)).Interior.ColorIndex = xlNone
        Range(Cells(xRow, 10), Cells(xRow, 12)).Interior.ColorIndex = xlNone
End If
prow = Selection.Row
xRow = prow

With Rng.Interior
    .ColorIndex = 34
    .Pattern = xlSolid
End With
Else
If xRow <> "" Then
        Range(Cells(xRow, 1), Cells(xRow, 7)).Interior.ColorIndex = xlNone
        Range(Cells(xRow, 10), Cells(xRow, 12)).Interior.ColorIndex = xlNone
End If
End If
End Sub
worked 100% as i want.. thank you very much
 

Forum statistics

Threads
1,144,392
Messages
5,724,078
Members
422,536
Latest member
Zeeshan53

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
Top