Trying to input an offset.

dhosi439

Board Regular
Joined
May 13, 2009
Messages
62
Here is the code I am using to select a value and change the color of the target, however the target I want to change the color of is the cell immediately to the right of the select case value.

For example, if the cell value in A1 is equal to cake, then B1 needs the cell color to change.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim icolor As Integer

    If Not Intersect(Target, Range("A1:A10")) Is Nothing Then

        Select Case Target

          Case "cake"

                 icolor = 9
                 
          Case "pie"
          
                 icolor = 11
                 
          Case Else

                 icolor = 22

         End Select
         
         Target.Interior.ColorIndex = icolor
         
    End If

End Sub
I'm thinking that the line of color setting the icolor needs to be offset, but I'm not sure how and if there would be any other snippets of code I would need to place into my existing code.

Any help would be great.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Change this line:
Code:
Target.Interior.ColorIndex = icolor

To this:
Code:
Target.Offset(ColumnOffset:=1).Interior.ColorIndex = icolor

Does that help?
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,315
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