+ Reply to Thread
Results 1 to 3 of 3

VBA Change color of cell next to another cell in column, given certain values

  1. #1
    Registered User
    Join Date
    07-03-2018
    Location
    Copenhagen, Denmark
    MS-Off Ver
    2013
    Posts
    2

    VBA Change color of cell next to another cell in column, given certain values

    Dear Excel forum - excel newbie here.

    I want to get conditional formating, and hence need to construct a code in VBA, that for a given column (or clomuns) makes a cell next to it a specific colour (e.g. red) given that the value of the column (or columns) is e.g 5 (or at least 5)

    The code i have tried so for looks as following, but doensīt seem to work at all - itīs constructed from copy/pasting other solutions, for similar problems:


    Private Sub colourChange(ByVal Target As Integer)


    On Error Resume Next

    If Target.Column = 7 Then

    If Taget.Value = 5 Then

    Application.EnableEvents = False

    Target.Offset(0, 4).Interior.ColorIndex = 3

    End If

    End If



    exitHandler:

    Application.EnableEvents = True

    Exit Sub


    End Sub


    Here i want a cell in colomn K to turn red, if a cell in column G in the same row has the value 5.


    I hope you can help me solve my problem,

    Thank you in advance

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,943

    Re: VBA Change color of cell next to another cell in column, given certain values

    I have assumed that you are entering values into column G (not using formulas):

    1) Copy this code.
    2) Right-Click the sheet tab of interest.
    3) Select "View Code"
    4) Paste the code into the window that appears.
    5) Save the file as a macro-enabled .xlsm file.


    Please Login or Register  to view this content.
    If you want to run a macro instead of using event code, then you could use this (which will work on constants or formulas in G):

    Please Login or Register  to view this content.
    Last edited by Bernie Deitrick; 07-03-2018 at 02:07 PM.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    07-03-2018
    Location
    Copenhagen, Denmark
    MS-Off Ver
    2013
    Posts
    2

    Re: VBA Change color of cell next to another cell in column, given certain values

    It works!!

    Thank you so much - you're an everyday hero! :D

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Change cell format (cell color+font color) based on color of another cell
    By Dedaluss in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-30-2017, 03:27 AM
  2. [SOLVED] Drop Down Values & Change Cell Color
    By yuenk in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-16-2016, 05:43 PM
  3. How to change the cell color based on the values
    By ancherilvm in forum Excel General
    Replies: 4
    Last Post: 04-16-2016, 02:30 PM
  4. [SOLVED] Change background color of cell if previous column cell value is different.
    By abhinavbinkar in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-21-2014, 08:25 AM
  5. Change cell color with different drop down values
    By Jonathan9 in forum Excel General
    Replies: 16
    Last Post: 06-20-2013, 06:37 AM
  6. Change cell color based on two values
    By jiub in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-20-2008, 10:56 PM
  7. [SOLVED] Change Whole Column Cell Color
    By Nigel Bennett in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-14-2005, 01:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1