Consulting

Results 1 to 6 of 6

Thread: VBA-highlight cell(s) in a column range if empty or greater than a value

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    VBA-highlight cell(s) in a column range if empty or greater than a value

    I am using Excel 2010 (x32). I am new to VBA and trying to create some VBA conditional formatting to be used as data validation. The first column is a data column. I want to fill a cell red if it is empty or orange if the cell is greater than a value in cell B4 on another sheet named "Instructions". I have created the following but it is not working. Any suggestions? Also, instead of the named range of "A2:A2552", can I use a do until or do while loop to accomodate a growing range?

    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim icolor As Integer
        Dim cell As Range
    
        If Intersect(Target, Range("A2:A2552")) Is Nothing Then Exit Sub
    
        For Each cell In Target
            icolor = 0
            Select Case cell
                Case Is > Range("Instructions!B4"): icolor = 3
                Case "": icolor = 45
            End Select
    
            If icolor <> 0 Then cell.Interior.ColorIndex = icolor
        Next cell
    End Sub
    Last edited by SamT; 11-12-2015 at 10:21 AM.

Tags for this Thread

Posting Permissions

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