+ Reply to Thread
Results 1 to 5 of 5

Changing cell color based on cell values

  1. #1
    Registered User
    Join Date
    08-28-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    2

    Changing cell color based on cell values

    Hi Guys,

    I have an excel sheet with 60 rows and 5 columns and I want to change the color of individual cells based on cell values.

    I'm posting a code below for this which seems to be working but still has some flaws in it. Please help me rectifying this code.



    Sub changecolor()

    Dim i, j As Integer
    For i = 1 To 60
    For j = 1 To 5
    If Cells(i, j) < 8 Then
    Cells(i, j).Interior.ColorIndex = 6
    Else: Cells(i, 1).Interior.ColorIndex = 8
    End If
    Next j
    Next i

    End Sub


    Or suggest me a better way to do this.

    Thanks,
    Prasanna

  2. #2
    Valued Forum Contributor
    Join Date
    08-14-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    573

    Re: Changing cell color based on cell values

    Hi Prasanna,

    I think in the else portion, you should have Cells(i,j).intereior.colorindex = 8.

    Regards,
    Sindhu

  3. #3
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,101

    Re: Changing cell color based on cell values

    Hello pkdash,

    Please read the Forum Rules, and wrap code that you post. Until you comply with this request and follow the Rules, you will not receive any help.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  4. #4
    Registered User
    Join Date
    08-28-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Changing cell color based on cell values

    Quote Originally Posted by pkdash View Post
    Hi Guys,

    I have an excel sheet with 60 rows and 5 columns and I want to change the color of individual cells based on cell values.

    I'm posting a code below for this which seems to be working but still has some flaws in it. Please help me rectifying this code.



    Sub changecolor()

    Dim i, j As Integer
    For i = 1 To 60
    For j = 1 To 5
    If Cells(i, j) < 8 Then
    Cells(i, j).Interior.ColorIndex = 6
    Else: Cells(i, 1).Interior.ColorIndex = 8
    End If
    Next j
    Next i

    End Sub


    Or suggest me a better way to do this.

    Thanks,
    Prasanna

    Great solved my problem, Thanks a lot Sindhu...

  5. #5
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,101

    Re: Changing cell color based on cell values

    Hello pkdash,

    Thank you for correcting your Post.

    You could use Conditional Formatting to achieve your objective without having to use VBA.

    If your problem is solved however, please do Mark your Thread as Solved.

    Thank you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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