Results 1 to 13 of 13

Macro for coloring cells based on contents

Threaded View

serge_kashlik Macro for coloring cells... 12-31-2017, 10:17 AM
jindon Re: Macro for coloring cells... 12-31-2017, 10:29 AM
davesexcel Re: Macro for coloring cells... 12-31-2017, 10:48 AM
serge_kashlik Re: Macro for coloring cells... 12-31-2017, 11:37 AM
jindon Re: Macro for coloring cells... 12-31-2017, 07:43 PM
serge_kashlik Re: Macro for coloring cells... 12-31-2017, 07:54 PM
jindon Re: Macro for coloring cells... 12-31-2017, 07:56 PM
serge_kashlik Re: Macro for coloring cells... 12-31-2017, 08:18 PM
jindon Re: Macro for coloring cells... 12-31-2017, 08:42 PM
serge_kashlik Re: Macro for coloring cells... 12-31-2017, 09:25 PM
jindon Re: Macro for coloring cells... 12-31-2017, 08:34 PM
jindon Re: Macro for coloring cells... 12-31-2017, 09:35 PM
serge_kashlik Re: Macro for coloring cells... 12-31-2017, 09:38 PM
  1. #1
    Registered User
    Join Date
    12-31-2017
    Location
    Moscow
    MS-Off Ver
    2013
    Posts
    8

    Macro for coloring cells based on contents

    I have the following macro

    Formula: copy to clipboard
    Sub ModelColoring()

    Dim cell As Range, constantCell As Range, formulaCells As Range
    Dim cellFormula As String

    With Selection
    On Error Resume Next
    Set constantCell = .SpecialCells(xlCellTypeConstants, xlNumbers)
    Set formulaCells = .SpecialCells(xlCellTypeFormulas, 21)
    On Error GoTo 0
    End With


    If Not constantCell Is Nothing Then
    constantCell.Font.Color = vbBlue
    End If

    If Not formulaCells Is Nothing Then
    For Each cell In formulaCells
    cellFormula = cell.Formula

    If cellFormula Like "*.xls*]*!*" Then
    cell.Font.Color = RGB(0, 176, 80)
    ElseIf cellFormula Like "*!*" _
    And Not cellFormula Like "*~**" _
    And Not cellFormula Like "*+*" _
    And Not cellFormula Like "*-*" _
    And Not cellFormula Like "*/*" _
    And Not cellFormula Like "*^*" _
    And Not cellFormula Like "*%*" _
    And Not cellFormula Like "*>*" _
    And Not cellFormula Like "*<*" _
    And Not cellFormula Like "*=<*" _
    And Not cellFormula Like "*=>*" _
    And Not cellFormula Like "*<>*" _
    And Not cellFormula Like "*&*" Then
    cell.Font.Color = vbRed
    Else
    cell.Font.Color = vbBlack
    End If
    Next cell
    End If

    End Sub

    I have problems with this line

    Formula: copy to clipboard
    And Not cellFormula Like "*~**"



    Basically I want all the cells with constants have one font color, those that perform a calculation to have another and those that derive their value from another sheet a third. However, the above mentioned line does not seem to recognize the multiplication symbol * for some reason and colors the cells that use values from other sheets and multiply them as if they are simply derived from another sheet (i.e. vbRed instead of black).

    I am still quite new to VBA so if anyone could help I would appreciate it.
    Thx in advance
    Attached Files Attached Files
    Last edited by serge_kashlik; 12-31-2017 at 07:53 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 22
    Last Post: 03-16-2017, 09:42 PM
  2. [SOLVED] I need a macro to clear cells based on contents
    By emymeeky in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-28-2013, 08:54 AM
  3. [SOLVED] Combining Contents of two cells whilst preserving text coloring
    By jordan2322 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-11-2013, 12:20 AM
  4. [SOLVED] Coloring cells based on value in another cell
    By killerthun in forum Excel General
    Replies: 2
    Last Post: 08-16-2012, 08:21 AM
  5. Coloring Cells dependent upon their contents
    By omgeokid in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-16-2011, 02:33 PM
  6. Macro to hide columns based on contents of two cells
    By Korae13 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-18-2006, 12:40 AM
  7. [SOLVED] Coloring Cell Font based on Cell Contents
    By willjohnson33@yahoo.com in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-22-2005, 08:06 PM

Tags for this Thread

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