Highlight offset 8th row 3 values, from the selected cell

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,371
Office Version
  1. 2010
Hello,

I requiresome solution to be highlighted offset 8th row 3 values, from the selected cell
Range to beselected in columns K:P, and highlighted range to be selected in columns C:H

For example...
If I selectK16, highlight the C14:C16
If I selectM31, "clear the highlighted range C14:C16" and highlight the E29:E31
If I selectP47, "clear the highlighted range E29:E31" and highlight the H45:H47

Note: ifselection is out of columns K:P, clear all highlights from columns C:G

Exampledata....


Book1
ABCDEFGHIJKLMNOPQ
1
2
3
4
5n1n2n3n4n5n6n1n2n3n4n5n6
630111342184304542
7292745331938212422
8234652233111433
921245124727211324
1046351882112211234
1135213745147311244
121815329227130242
133811465139231342
14454230938252422
154510186310332424
163162221146321425
17
18
19
20n1n2n3n4n5n6n1n2n3n4n5n6
2130111342184304542
22292745331938212422
23234652233111433
2421245124727211324
2546351882112211234
2635213745147311244
271815329227130242
283811465139231342
29454230938252422
304510186310332424
313162221146321425
32
33
34
35
36n1n2n3n4n5n6n1n2n3n4n5n6
3730111342184304542
38292745331938212422
39234652233111433
4021245124727211324
4146351882112211234
4235213745147311244
431815329227130242
443811465139231342
45454230938252422
464510186310332424
473162221146321425
48
49
Sheet1



Thank youall
Excel 2000
Regards,
Moti
 
Last edited:

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Try:-
Code:
Private [COLOR="Navy"]Sub[/COLOR] Worksheet_SelectionChange(ByVal Target [COLOR="Navy"]As[/COLOR] Range)
[COLOR="Navy"]If[/COLOR] Not Intersect(Target, Columns("K:P")) [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR]
    [COLOR="Navy"]If[/COLOR] Target <> "" [COLOR="Navy"]Then[/COLOR]
        Target.Offset(-2, -8).Resize(3).Interior.Color = vbYellow
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]ElseIf[/COLOR] Intersect(Target, Columns("K:P")) [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR]
     Range("C:F").Interior.Color = xlNone
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$K$16" Or _
   Target.Address = "$M$31" Or _
   Target.Address = "$P$47" Then
Application.EnableEvents = False
Target.Offset(-2, -8).Resize(3, 1).Select
Application.EnableEvents = True
End If
End Sub
 
Upvote 0
Try:-
Code:
Private [COLOR=Navy]Sub[/COLOR] Worksheet_SelectionChange(ByVal Target [COLOR=Navy]As[/COLOR] Range)
[COLOR=Navy]If[/COLOR] Not Intersect(Target, Columns("K:P")) [COLOR=Navy]Is[/COLOR] Nothing [COLOR=Navy]Then[/COLOR]
    [COLOR=Navy]If[/COLOR] Target <> "" [COLOR=Navy]Then[/COLOR]
        Target.Offset(-2, -8).Resize(3).Interior.Color = vbYellow
    [COLOR=Navy]End[/COLOR] If
[COLOR=Navy]ElseIf[/COLOR] Intersect(Target, Columns("K:P")) [COLOR=Navy]Is[/COLOR] Nothing [COLOR=Navy]Then[/COLOR]
     Range("C:F").Interior.Color = xlNone
[COLOR=Navy]End[/COLOR] If
[COLOR=Navy]End[/COLOR] [COLOR=Navy]Sub[/COLOR]
Regards Mick
Hello Mick, It's working perfect! Only when I select multiple cells in the range K:P highlights the following row in the code, is it possible avoid this error
Code:
If Target <> "" Then

Thank you for your help

Kind Regards,
Moti
 
Upvote 0
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$K$16" Or _
   Target.Address = "$M$31" Or _
   Target.Address = "$P$47" Then
Application.EnableEvents = False
Target.Offset(-2, -8).Resize(3, 1).Select
Application.EnableEvents = True
End If
End Sub
Hello jim may, I tried the code but it don't highlight any cells.

Please could you check?

Thank you for your help

Kind Regards,
Moti
 
Upvote 0
Try this:-
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count = 1 Then
If Not Intersect(Target, Columns("K:P")) Is Nothing Then
    If Target <> "" Then
        Range("C:H").Interior.Color = xlNone
        Target.Offset(-2, -8).Resize(3).Interior.Color = vbYellow
    End If
ElseIf Intersect(Target, Columns("K:P")) Is Nothing Then
     Range("C:H").Interior.Color = xlNone
End If
End If
End Sub
Regrds Mick
 
Last edited:
Upvote 0
Hello jim may, I tried the code but it don't highlight any cells.

Please could you check?

Thank you for your help

Kind Regards,
Moti

Note the code-line:
Target.Offset(-2, -8).Resize(3, 1).Select

Note the last word Select. This should HIGHLITE THE RANGE..

Step through the full code to view what happening with each code-line.

It works for me!!!
 
Upvote 0
Try this:-
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count = 1 Then
If Not Intersect(Target, Columns("K:P")) Is Nothing Then
    If Target <> "" Then
        Range("C:H").Interior.Color = xlNone
        Target.Offset(-2, -8).Resize(3).Interior.Color = vbYellow
    End If
ElseIf Intersect(Target, Columns("K:P")) Is Nothing Then
     Range("C:H").Interior.Color = xlNone
End If
End If
End Sub
Regrds Mick
Mick, Yes that's exactly as I wanted, it's perfect!

Thanks a lot once again!!

Kind Regards,
Moti
:)
 
Upvote 0
Note the code-line:
Target.Offset(-2, -8).Resize(3, 1).Select

Note the last word Select. This should HIGHLITE THE RANGE..

Step through the full code to view what happening with each code-line.

It works for me!!!
Sorry jim may, yes it is working if I select the ranges as I specified in the example post#1, because I did not clarified and selection in the range K:P

Thank you for the clarification and help

Kind Regards,
Moti
 
Upvote 0
Mick, Yes that's exactly as I wanted, it's perfect!
:)
Is it? I presumed if you selected a cell near the top of the right-hand filled range, or if you selected a cell in the title row itself, that you would not want the selection in the other filled range to color the title row or blank cells above it. Mick's code colors those cells for such a selection... the following SelectChange event accounts doesn't.
Code:
[table="width: 500"]
[tr]
	[td]Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  Dim TopRow As Long, Cell As Range, Rng As Range, IntersectRng As Range
  Range("C:H,K:P").Interior.ColorIndex = xlColorIndexNone
  Set Rng = Intersect(Target, Columns("K:P"))
  If Not Rng Is Nothing Then
    TopRow = Rng.CurrentRegion.Row
    For Each Cell In Rng
      If IsNumeric(Cell.Value) And Cell.Value <> "" Then
        Cell.Interior.Color = vbYellow
        Intersect(Cell.CurrentRegion.Offset(1, -8), Cell.Offset(-2, -8).Resize(3)).Interior.Color = vbYellow
      End If
    Next
  End If
End Sub[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,992
Messages
6,128,170
Members
449,429
Latest member
ianharper68

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