+ Reply to Thread
Results 1 to 2 of 2

Formatting based on count statement

Hybrid View

  1. #1
    Registered User
    Join Date
    02-27-2014
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    25

    Formatting based on count statement

    VBA Code to count how many cells in column G contain a number greater than 0.

    Then put All Borders around F4:J4 on a different sheet, going down the amount of rows from the first number.

    So for example, if column G contains 6 numbers that are greater than 0, then format all borders around F4:J9

    Thanks

  2. #2
    Forum Contributor
    Join Date
    12-09-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    171

    Re: Formatting based on count statement

    Try this

    
    Sub CFormat()
        Dim i, c, lrow As Integer
        Dim rng As Range
        lrow = Sheets("sheet1").Cells(Rows.Count, 7).End(xlUp).Row
        c = 0
        For Each rng In Sheets("sheet1").Range("G1:G" & lrow)
                If rng.Value > 0 Then c = c + 1
        Next rng
        
        Sheets("Sheet1").Range("F4:J" & 4 + c).Select
        
        Selection.Borders(xlDiagonalDown).LineStyle = xlNone
        Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With Selection.Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlThin
        End With
        With Selection.Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlThin
        End With
        With Selection.Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlThin
        End With
        With Selection.Borders(xlEdgeRight)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlThin
        End With
        With Selection.Borders(xlInsideVertical)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlThin
        End With
        With Selection.Borders(xlInsideHorizontal)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlThin
        End With
        
    End Sub
    Like my answer, then click * below

+ 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. Stacked Conditional Formatting based on values from an IF statement?
    By nscarritt in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 12-21-2013, 11:24 AM
  2. Replies: 2
    Last Post: 10-02-2013, 04:31 PM
  3. Replies: 1
    Last Post: 10-02-2013, 02:36 PM
  4. Count based on formatting, not value
    By dtrimble in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-13-2012, 12:52 PM
  5. Conditional formatting based on if statement.
    By kevin in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-12-2005, 12:06 AM

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