+ Reply to Thread
Results 1 to 6 of 6

Highlighting a Cell, based on value / blank.

Hybrid View

robert_shindorf Highlighting a Cell, based on... 12-29-2008, 06:42 PM
Richard Buttrey Hi, Perhaps If... 12-29-2008, 06:55 PM
robert_shindorf ahhh ha! I was trying to... 12-29-2008, 06:59 PM
robert_shindorf woops, looks like one more... 12-29-2008, 07:09 PM
Richard Buttrey Hi, Assuming you're... 12-29-2008, 07:29 PM
robert_shindorf you were absolutely right...... 12-29-2008, 07:42 PM
  1. #1
    Forum Contributor
    Join Date
    06-29-2008
    Location
    Grand Rapids, MI
    MS-Off Ver
    Office 2010
    Posts
    127

    Highlighting a Cell, based on value / blank.

    Hi folks..

    I have a macro, and it mainly works, except the second part where it checks if the value is less than 7, and returns it to a white background.

    The cell has a formula in it that returns "" based on another series of cells. I have considered changing that to a zero and formating, but for reasons that don't need explanation, i have chosen not to.

    here is the macro. I need the second part to be activated if less than 7, as well as if the cell returns ""

    Private Sub Worksheet_Change(ByVal Target As Range)
    Application.ScreenUpdating = False
    Dim lrow As Long
    Dim i As Integer
    Dim WSRec As Worksheet
    Set WSRec = Sheets("Payables")
    lrow = WSRec.Range("f65536").End(xlUp).Row
    For i = 13 To lrow
        If WSRec.Cells(i, 10).Value > 7 Then
            WSRec.Cells(i, 10).Select
            With Selection.Font
                .FontStyle = "Bold"
            End With
            With Selection.Interior
              .Color = 255
            End With
        End If
            If WSRec.Cells(i, 10).Value < 7 Then
            WSRec.Cells(i, 10).Select
            With Selection.Font
                .FontStyle = "Regular"
            End With
            With Selection.Interior
              .Color = RGB(255, 255, 255)
            End With
        End If
    Next
    End Sub
    Thanks in advance.
    Last edited by robert_shindorf; 12-29-2008 at 07:42 PM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464
    Hi,

    Perhaps

    
    If WSRec.Cells(i, 10).Value < 7 OR WSRec.Cells(i, 10).Value ="" Then
    HTH

  3. #3
    Forum Contributor
    Join Date
    06-29-2008
    Location
    Grand Rapids, MI
    MS-Off Ver
    Office 2010
    Posts
    127
    ahhh ha!

    I was trying to write it like a formula or(condition1, consition2)

    haha, thanks!

  4. #4
    Forum Contributor
    Join Date
    06-29-2008
    Location
    Grand Rapids, MI
    MS-Off Ver
    Office 2010
    Posts
    127
    woops, looks like one more thing is happening, when the workbook changes, it moves the selected cell to column 10, is there something i can add to the end to keep the selection where it is?

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464
    Quote Originally Posted by robert_shindorf View Post
    woops, looks like one more thing is happening, when the workbook changes, it moves the selected cell to column 10, is there something i can add to the end to keep the selection where it is?
    Hi,

    Assuming you're talking about column F being the active colum,

    Range("F" & lRow).Select
    But I can't help thinking you're better not selecting column 10 in the first place. Try and avoid .Select and .Activate.

    Try just

    
    With WSRec.Cells(i, 10)
      .Font.FontStyle = "Bold"
      .Interior.Color = 255
     End With
    HTH

  6. #6
    Forum Contributor
    Join Date
    06-29-2008
    Location
    Grand Rapids, MI
    MS-Off Ver
    Office 2010
    Posts
    127
    you were absolutely right... avoiding selecting that cell was better a better bet.

    thanks again.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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