+ Reply to Thread
Results 1 to 11 of 11

Colouring rows based on their values

  1. #1
    Registered User
    Join Date
    11-09-2011
    Location
    Central, Hong Kong
    MS-Off Ver
    Excel 2010
    Posts
    49

    Colouring rows based on their values

    So I am just trying to solve a simplified version of my problem. If row a-b = an integer then highlight blue say, if a-b doesn't = integer then do (a-b) * c. If (a-b)*c = integer highlight green if not highlight red.

    I'm not much of a vba expert, so my code may look slightly overcomplicated... but I'm not sure why it doesn't work...


    Please Login or Register  to view this content.
    thanks in advance!

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Colouring rows based on their values

    Hello,

    Why are you trying to reinvent the wheel when there is very powerful standard Excel conditional formatting functionality?

    You should always use standard Excel functions and formulae in preference to VBA wherever possible. If only because it's almost certainly quicker.

    Regards
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,501

    Re: Colouring rows based on their values

    The first problem is that ar is not defined.

    I would recommend that you use Option Explicit at the top of the module.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Registered User
    Join Date
    11-09-2011
    Location
    Central, Hong Kong
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: Colouring rows based on their values

    Quote Originally Posted by Richard Buttrey View Post
    Hello,

    Why are you trying to reinvent the wheel when there is very powerful standard Excel conditional formatting functionality?

    You should always use standard Excel functions and formulae in preference to VBA wherever possible. If only because it's almost certainly quicker.

    Regards
    Hi Richard thanks for the reply,
    This example is a simplified version of what I actually want to achieve, conditional formatting is not an option in the more complex version I'm afraid. But I am aware that what I want to do in the simple version can be done w. conditional formatting.

    D'you know how I could alter my code? Or if this is overcomplicated - a more simple version of solving the same predicament.

    Cheers.

  5. #5
    Registered User
    Join Date
    11-09-2011
    Location
    Central, Hong Kong
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: Colouring rows based on their values

    Quote Originally Posted by TMShucks View Post
    The first problem is that ar is not defined.

    I would recommend that you use Option Explicit at the top of the module.

    Regards, TMS
    Thanks for the reply,
    seems I did miss that out thank you - but I think theres more problems, that I personally can't see.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,501

    Re: Colouring rows based on their values

    Maybe something like:

    Please Login or Register  to view this content.

    I can't test this ... no data.


    Regards, TMS

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,501

    Re: Colouring rows based on their values

    That said, you're referring to the ActiveCell but I can't see where you ever select a cell.


    Regards, TMS

  8. #8
    Registered User
    Join Date
    11-09-2011
    Location
    Central, Hong Kong
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: Colouring rows based on their values

    So data from A1:C36 (All values in this are +ve integers).


    -As for the activecell, thanks for pointing that out - I've never done highlighting rows etc. so I'm not sure how to do it and copied that line off a website.


    - as for rz = .rows.count, doesn't seem to work in these circumstances. I think i've defined the previous array incorrectly.

    Thanks!

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,501

    Re: Colouring rows based on their values

    Please post a sample workbook. Being realistic, I can't make up data and test code that I have no idea how it interacts with the data and structure.

    Regards, TMS

    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook. Don't upload a picture when you have a workbook question. None of us is inclined to recreate your data. Upload the workbook and manually add an 'after' situation so that we can see what you expect. In addition clearly explain how you get the results..
    To attach a file to your post, you need to be using the main 'New Post' or 'New Thread' page and not 'Quick Reply'.
    To use the main 'New Post' page, click the 'Post Reply' button in the relevant thread.

    On this page, below the message box, you will find a button labelled 'Manage Attachments'.
    Clicking this button will open a new window for uploading attachments.

    You can upload an attachment either from your computer or from another URL by using the appropriate box on this page.
    Alternatively you can click the Attachment Icon to open this page.

    To upload a file from your computer, click the 'Browse' button and locate the file.

    To upload a file from another URL, enter the full URL for the file in the second box on this page.
    Once you have completed one of the boxes, click 'Upload'.

    Once the upload is completed the file name will appear below the input boxes in this window.
    You can then close the window to return to the new post screen.

  10. #10
    Registered User
    Join Date
    11-09-2011
    Location
    Central, Hong Kong
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: Colouring rows based on their values

    For now just assume they are random numbers (see attached).

    The real thing has formulae, but because the formula generates a number, there wont be any problems regarding formula. (I would post a version with the formula but this formula requires data from an external program).


    -Thanks again!
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    11-09-2011
    Location
    Central, Hong Kong
    MS-Off Ver
    Excel 2010
    Posts
    49

    Re: Colouring rows based on their values

    any ideas?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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