highlight active cell Row till "M"

Jagat Pavasia

Active Member
Joined
Mar 9, 2015
Messages
359
Office Version
  1. 2021
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
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
try
VBA Code:
Range(Cells(prow, 1), Cells(prow, 13)).Interior
instead of
VBA Code:
Rows(pRow).Interior

HTH...
 
Upvote 0
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

Hello, if I understand correctly, this will fix your problem.

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

Dim sh As Worksheet
Dim rg As Range

Static xRow As Long
Dim pRow As Long

Set sh = Sheets("Sheet2")

If xRow <> 0 Then
    With rows(xRow).Interior
        .ColorIndex = xlNone
    End With
End If

pRow = Target.Row
xRow = pRow

Set rg = sh.Range("A" & pRow & ":M" & pRow)

With rg.Interior
    .ColorIndex = 34
    .Pattern = xlSolid
End With
End Sub
 
Upvote 0
Hello, if I understand correctly, this will fix your problem.

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

Dim sh As Worksheet
Dim rg As Range

Static xRow As Long
Dim pRow As Long

Set sh = Sheets("Sheet2")

If xRow <> 0 Then
    With rows(xRow).Interior
        .ColorIndex = xlNone
    End With
End If

pRow = Target.Row
xRow = pRow

Set rg = sh.Range("A" & pRow & ":M" & pRow)

With rg.Interior
    .ColorIndex = 34
    .Pattern = xlSolid
End With
End Sub
VBA code error with yellow highlight at "Set sh = Sheets("Sheet2")"
 
Upvote 0
please edit my VBA code, because I am new in VBA coding....please
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 Range(Cells(prow, 1), Cells(prow, 13)).Interior
    .ColorIndex = 34
    .Pattern = xlSolid
End With
End Sub
 
Upvote 0
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 Range(Cells(prow, 1), Cells(prow, 13)).Interior
    .ColorIndex = 34
    .Pattern = xlSolid
End With
End Sub
YES, THANK YOU SO MUCH,

IT IS WORKING AS I WANT...


THANK YOU FOR HELP
 
Upvote 0
You're welcome, glad we could help...
 
Upvote 0

Forum statistics

Threads
1,215,343
Messages
6,124,400
Members
449,156
Latest member
LSchleppi

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