Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50158

Conditional Formatting vba

$
0
0
I'll try do (the macro is necessary because users can change or remove formatting):

The first row of a sheet has headings;
Column A (from 2 row and below) text (VerticalAlignment=xlCenter, HorizonalAlignment=xlLeft, text style bold)
Range A2:CV - data (numbers from 0 to 2, manually sets). Need to apply IconSets(xl3Symbols2) to this range. VerticalAlignment=xlCenter, HorizonalAlignment=xlCenter, text style bold)
All range A:CV must be formatted with borders xlContinuous and weight xlHairline

Can any analyse my macro?

vba code
Code:

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim cfIconSet As IconSetCondition
    Dim iRow As Long, i As Long, f As Long
      If Not Intersect(Range("A:CV"), Target) Is Nothing Then
      Cells.Borders.LineStyle = xlNone
      iRow = Range("A2:CV)" & Rows.Count).End(xlUp).Row
          If iRow > 1 Then
          Set IRange = Range("A:CV" & iRow)
          Set CRange = Range("A2:CV" & iRow)
          IRange.Borders.LineStyle = xlContinuous
          IRange.Borders(xlInsideHorizontal).LineStyle = xlContinuous
          IRange.Borders(xlInsideVertical).LineStyle = xlContinuous
          IRange.Borders.Weight = xlHairline
          Set cfIconSet = CRange.FormatConditions.AddIconSetCondition
        cfIconSet.IconSet = ActiveWorkbook.IconSets(xl3Symbols2)
          With cfIconSet.IconCriteria(2)
            .Type = xlConditionValueNumber
            .Value = 0
            .Operator = 7
            End With
          With cfIconSet.IconCriteria(2)
            .Type = xlConditionValueNumber
            .Value = 1
            .Operator = 7
          End With
        With cfIconSet.IconCriteria(2)
            .Type = xlConditionValueNumber
            .Value = 2
              .Operator = 7
        End With
    End If
    For Each iTarget In Target
  Set UFRange = Range("A" & iTarget.Row & ":CV" & iTarget.Row)
          Set UF1Range = Range("A" & iTarget.Row)
          With UFRange
              .Interior.ColorIndex = i
              .Font.ColorIndex = f
              .VerticalAlignment = xlCenter
           
              .Font.Name = "Verdana"
              .Font.Size = 8
          End With
          With UF1Range
              .Font.Bold = True
           
          End With
 Next
  End If
End Sub


Viewing all articles
Browse latest Browse all 50158

Trending Articles