Consulting

Results 1 to 4 of 4

Thread: Distinguish between two similar values

  1. #1
    VBAX Mentor
    Joined
    Aug 2011
    Posts
    353
    Location
    The code I have is meant to leave the first two A1, the first two A2, etc..
    But now I want to distinguish between each. How do i have the first A1, A2, A3, etc.. be highlighted in yellow and the second A1, A2, A3, etc...be renamed "cover"? I have a formula for this but it is too specific for the rows.
    [vba]Sub highlight()
    '
    ' highlight Macro
    '
    '
    Rows("2:2").Select
    With Selection.Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .Color = 65535
    .TintAndShade = 0
    .PatternTintAndShade = 0
    End With
    Rows("4:4").Select
    With Selection.Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .Color = 65535
    .TintAndShade = 0
    .PatternTintAndShade = 0
    End With
    Rows("6:6").Select
    With Selection.Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .Color = 65535
    .TintAndShade = 0
    .PatternTintAndShade = 0
    End With
    Rows("8:8").Select
    With Selection.Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .Color = 65535
    .TintAndShade = 0
    .PatternTintAndShade = 0
    End With
    Rows("10:10").Select
    With Selection.Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .Color = 65535
    .TintAndShade = 0
    .PatternTintAndShade = 0
    End With
    Rows("12:12").Select
    With Selection.Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .Color = 65535
    .TintAndShade = 0
    .PatternTintAndShade = 0
    End With
    End Sub
    [/vba] I need a more general formula that references each top A1, A2, A3, etc...

    Thank you so much for your help! Greatly appreciate.
    Last edited by Aussiebear; 08-31-2011 at 03:10 PM. Reason: Added vba tags to code

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Sub highlight()
    Dim lastrow As Long
    Dim i As Long

    With ActiveSheet

    lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
    For i = 1 To lastrow

    If Application.CountIf(.Range("A1").Resize(i), .Cells(i, "A").Value) = 1 Then

    With .Cells(i, "A").Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .Color = 65535
    .TintAndShade = 0
    .PatternTintAndShade = 0
    End With
    End If
    Next i
    End With
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Mentor
    Joined
    Aug 2011
    Posts
    353
    Location
    Thanks that works! Can you help me write a macro that renames the second A1, A2, A3, etc.. the word "cover"

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Sub highlight()
    Dim lastrow As Long
    Dim i As Long

    With ActiveSheet

    lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
    For i = 1 To lastrow

    If Application.CountIf(.Range("A1").Resize(i), .Cells(i, "A").Value) = 1 Then

    With .Cells(i, "A").Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .Color = 65535
    .TintAndShade = 0
    .PatternTintAndShade = 0
    End With
    ElseIf Application.CountIf(.Range("A1").Resize(i), .Cells(i, "A").Value) = 2 Then

    .Cells(i, "A").Value = "cover"
    End If
    Next i
    End With
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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