Consulting

Results 1 to 3 of 3

Thread: Highlighting Row

  1. #1
    VBAX Regular
    Joined
    Nov 2011
    Posts
    10
    Location

    Highlighting Row

    Dear all,

    I am a newbie in VBA and encounter a problem. Please help me.

    My excel sheet has several columns and hundred rows. Each column represents different items (eg.: Invoice number, transaction date, completion etc). Now I would like to create a VBA which will search the "Completion" column (Column C) for the word of "Completed". When it is "completed", then that row (from Column A to Column I) will be filled with color in order to easily search uncompleted transaction.

    Since I am too superficial, what I can do is just highlight the "completed" cell only :<

    Belows are what I wrote


    Sub Highlight()

    Dim clnC As Range
    Dim clcell As Range

    Set clnC = Range("C9:C10000")

    For Each clcell In clnC

    If clcell.Value = "Completed" Then
    clcell.Select
    With Selection.Interior
    .ColorIndex = 36
    .Pattern = xlSolid
    End With

    End If

    Next clcell

    End Sub

    Thanks in advance for your help.

  2. #2
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    try this out:
    [VBA]
    Sub Highlight()
    Dim LastRow As Long
    Dim InputSheet As Worksheet
    Dim lRow As Long

    Set InputSheet = Worksheets("Sheet1")

    LastRow = FindLastRow(InputSheet, "C")
    For lRow = 9 To LastRow
    If UCase(InputSheet.Cells(lRow, "C")) = "COMPLETED" Then
    InputSheet.Range("A" & lRow & ":I" & lRow).Interior.ColorIndex = 6
    End If
    Next lRow

    Set InputSheet = Nothing
    End Sub
    Public Function FindLastRow(ByVal WS As Worksheet, ColumnLetter As String) As Long
    ' This function will fine the last row based on the Column that is sent to it.
    FindLastRow = WS.Range(ColumnLetter & "65536").End(xlUp).Row
    End Function
    [/VBA]

  3. #3
    VBAX Regular
    Joined
    Nov 2011
    Posts
    10
    Location
    Dear JKawn,

    Thank you very much. I really appreciate your help. But first thing...let me digest your work first : )

    Thanks again!

Posting Permissions

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