Target Value from another sheet.

erutherford

Active Member
Joined
Dec 19, 2016
Messages
453
I currently have the following code in "worksheet"/SelectionChange and it works fine. I am sure there is a simpler to way to write the code, but right now it easier to find code and modify it.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
       If Intersect(Target, Range("I:I")) Is Nothing Then Exit Sub 'check for range
    If Target.Value = "W" Then 'check if "W"
        Target.Offset(0, 6).Interior.ColorIndex = 1 ' "1"=Black
        Target.Offset(0, 7).Interior.ColorIndex = 1
        Target.Offset(0, 6).Font.ColorIndex = 3 ' "3"=Red
        Target.Offset(0, 7).Font.ColorIndex = 3 ' "3"=Red
    ElseIf Target.Value = "S" Then 'check if "S"
        Target.Offset(0, 6).Interior.ColorIndex = 1 ' "1"=Black
        Target.Offset(0, 7).Interior.ColorIndex = 1
        Target.Offset(0, 6).Font.ColorIndex = 3 ' "3"=Red
        Target.Offset(0, 7).Font.ColorIndex = 3 ' "3"=Red
    Else
        Target.Offset(0, 6).Interior.ColorIndex = 27
        Target.Offset(0, 7).Interior.ColorIndex = 27
        Target.Offset(0, 6).Font.ColorIndex = 1
        Target.Offset(0, 7).Font.ColorIndex = 1
    End If
End Sub

In column I there is code
Code:
=Entries!I1

Target.value doesn't like reading that code. If I delete the code and just enter the letter it works fine. I need it to run off the formula.

Thanks in advance
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Change events don't work if the cell value is a formula.
Is col I on the Entries sheet manually entered or another formula?
 
Upvote 0
Manually entered in on "Entries" sheet. I was thinking that might be the answer is to point the code there, just didn't quite know how to do it.
 
Upvote 0
I've done the first section, to show how it's done
Put this on the Entries sheet
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Intersect(Target, Range("I:I")) Is Nothing Then Exit Sub 'check for range
   [COLOR=#0000ff]With Sheets("[/COLOR][COLOR=#ff0000]Project[/COLOR][COLOR=#0000ff]")[/COLOR]
      If Target.Value = "W" Then 'check if "W"
          [COLOR=#0000ff].Range(Target.Offset(0, 6).Address).Resize(, 2).Interior.ColorIndex = 1 ' "1"=Black
          .Range(Target.Offset(0, 6).Address).Resize(, 2).Font.ColorIndex = 3 ' "3"=Red[/COLOR]
      ElseIf Target.Value = "S" Then 'check if "S"
          Target.Offset(0, 6).Interior.ColorIndex = 1 ' "1"=Black
          Target.Offset(0, 7).Interior.ColorIndex = 1
          Target.Offset(0, 6).Font.ColorIndex = 3 ' "3"=Red
          Target.Offset(0, 7).Font.ColorIndex = 3 ' "3"=Red
      Else
          Target.Offset(0, 6).Interior.ColorIndex = 27
          Target.Offset(0, 7).Interior.ColorIndex = 27
          Target.Offset(0, 6).Font.ColorIndex = 1
          Target.Offset(0, 7).Font.ColorIndex = 1
      End If
   End With
End Sub
Change sheet name in red to suit
 
Upvote 0
Just to be clear we are on the same page

The "entries" sheet in col I are manually entered ("F"or"W","S").
On sheet "Scores" in Col I, cells get there values from the entries sheet via "=entries!I1, I2" etc.
Columns "6" and "7" are manipulated based on the value in sheet "Scores" in Col I.

But that won't work as you stated above.

I pasted the new code in the "entries" worksheet and it executes on that page, but not in the "scores" sheets

In the above modified code, where is the sheet "scores" referenced? I probably didn't explain it clear.
 
Upvote 0
You need to change the sheet name I highlighted in red to "Scores"
At the moment it will only work on the "W" values, you need to modify the other sections, in the same manner.
 
Upvote 0
Ok it works now and I'll modify the rest no problem.

With Sheets("Scores") is pointing to our destination. What is ".address.Resize doing?

I like to at least understand a little about what is happening.

Thanks for helping out of course Fluff!
 
Upvote 0
This
Code:
[COLOR=#0000ff]Target.Offset(0, 6).Address[/COLOR]
returns the address of the the cell 6 columns to the right of the target. So if the target cell was I5 you will get $O$6 which then means that this
Code:
.Range(Target.Offset(0, 6).Address).Resize(, 2)
Is Range($O$5) and the Resize then changes the size of the range to make it 2 cells wide ie O5:P5
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,312
Members
452,634
Latest member
cpostell

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