VBA code to change color of text based on location of active cell?

EssKayKay

Active Member
Joined
Jan 5, 2003
Messages
413
Office Version
  1. 2007
Platform
  1. Windows
Hello,

I have a question related to previous posting if you please.

I am looking for way to change the color of the text in a cell in column C based on the cell that is active in column I for the corresponding row. That is, if cell I44 is the active cell, then the text in cell C44 changes to red.

I have coding I received elsewhere that does this for a different column relationship (I apologize to the author as I don’t exactly remember who gave this to me). As example, in my current code, if the active cell is M55 then the text in C55 changes to red. I’d like a similar thing to happen if the active cell is in column I.

Here is my existing code. Please note, the proposed code does not have to be the same as the current. I simply posted it as an example. If you have a different idea that’s fine –

VBA Code:
Option Explicit
Public Old As Integer
Public Now As Integer

‘- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    If Not Intersect(target, Range("M32:M2032")) Is Nothing Then
      Now = (Split(ActiveCell(1).Address(1, 0), "$")(1))
          If (Old <> Now) Then
             UnProtect_It
             Range(Cells(Now, 3), Cells(Now, 3)).Font.Color = vbRed
             If Old Then Range(Cells(Old, 3), Cells(Old, 3)).Font.Color = False
             Range(Cells(Now, 3), Cells(Now, 3)).Font.Bold = True
             If Old Then Range(Cells(Old, 3), Cells(Old, 3)).Font.Bold = False
             Protect_It
          End If
       Old = Now
    End If

Thanks for viewing,
Steve K.
 
Thank you all very much for your input. With a little adjustment I have this working perfectly.

Again, my sincere appreciation,
Steve
 
Upvote 0

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
OOPS - I may have spoken too soon (could not edit). I ran into a few more issues. I'll keep working on it and be back with my results.
Keeping my fingers crossed. . .
 
Upvote 0
Got it. I had to rearrange some coding in my Worksheet_SelectionChange sub. Seems to be doing what I want now.
As noted, you all are most certainly appreciated. . .
 
Upvote 0
You're welcome, glad to help & thanks for the feedback.:)
 
Upvote 0

Forum statistics

Threads
1,224,709
Messages
6,180,469
Members
452,986
Latest member
zenki1

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