+ Reply to Thread
Results 1 to 15 of 15

Highlight noncontiguous ranges of cells

  1. #1
    Registered User
    Join Date
    07-25-2008
    Location
    Bend, Oregon
    Posts
    39

    Highlight noncontiguous ranges of cells

    Hi folks, I’m a relative armature at VB code and was hoping for some more great help. I want to select noncontiguous ranges of cells and highlight them with grey. The cells would all be in the same column but rows would be skipped between ranges. The rows are constant so could be hard coded but I’m going to pass the column to the procedure which I think I already know how to do. I just can’t figure out how to identify the cells I want to highlight and how to highlight them. Also, If I can do it without actually physically selecting the cells it would be better. Something like this:

    Please Login or Register  to view this content.
    But referenced something like this:

    Please Login or Register  to view this content.
    Thanks in advance for the help.
    And sorry if my code tags don't work, it's been a while since I have been here.
    Last edited by TrafficGuy; 02-16-2011 at 12:03 PM.

  2. #2
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Highlight noncontiguous ranges of cells

    hi, posting example workbook will be helpful

  3. #3
    Registered User
    Join Date
    07-25-2008
    Location
    Bend, Oregon
    Posts
    39

    Re: Highlight noncontiguous ranges of cells

    Thanks for the suggestion but the workbook is a company timesheet that I can’t distribute.

  4. #4
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Highlight noncontiguous ranges of cells

    as you understand we are not seeking to obtain sensitive company data. You can "desensitize" the data but not change it's type, example: digit replaced with digit, text with any other text etc. The example workbook can have 10-20 rows but then indicate max possible number of rows with data.

  5. #5
    Registered User
    Join Date
    07-25-2008
    Location
    Bend, Oregon
    Posts
    39

    Re: Highlight noncontiguous ranges of cells

    Thanks again, I’m not trying to be difficult here and appreciate all the help I have gotten, and I understand that if the workbook contained any relevant information it would be helpful but I’m just working on this, there isn’t anything in the workbook of any value to this question.

    All I’m asking is the syntax and methods I might use to say hey take this cell range over here and that cell range over there and set the color to light grey. And to reference noncontiguous ranges by column and row rather than cell say ("F14:F24,F28:F35",F38:F45).

    Or a reference to anything similar, I searched the archive but can’t find anything similar.

    Thanks again.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Highlight noncontiguous ranges of cells

    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  7. #7
    Registered User
    Join Date
    07-25-2008
    Location
    Bend, Oregon
    Posts
    39

    Re: Highlight noncontiguous ranges of cells

    Quote Originally Posted by shg View Post
    Please Login or Register  to view this content.
    Thank you, that’s pretty close to what I need. I have two questions, what would the syntax look like if I wanted to use a variable, column number for the column rather that F:F, and is there somewhere I can look up various acceptable combinations of syntax for the range method so I can learn this a little better?

    For example:
    Please Login or Register  to view this content.

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Highlight noncontiguous ranges of cells

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    07-25-2008
    Location
    Bend, Oregon
    Posts
    39

    Re: Highlight noncontiguous ranges of cells

    Quote Originally Posted by shg View Post
    Please Login or Register  to view this content.
    Thanks again, and I hate to waste your time but I don’t see how that would work using column numbers, I understand the variable as a representation of a text string but I need to provide it a column number.

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Highlight noncontiguous ranges of cells

    Rather than me guess a third time what you want, might you please explain in detail and include examples?

    Thanks.

  11. #11
    Registered User
    Join Date
    07-25-2008
    Location
    Bend, Oregon
    Posts
    39

    Re: Highlight noncontiguous ranges of cells

    OK, this is just an example, there will be some other testing going on to determine if the color should be changed or not so this doesn’t make much since but here is the idea.

    I simply put the variable Column in your line of code, it’s obviously not correct syntax but hopefully you get what I’m trying to do.

    Thanks again

    Please Login or Register  to view this content.

  12. #12
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Highlight noncontiguous ranges of cells

    You don't need a loop to do that:

    Please Login or Register  to view this content.
    ... or just ...
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    07-25-2008
    Location
    Bend, Oregon
    Posts
    39

    Re: Highlight noncontiguous ranges of cells

    Thanks again. I am sorry I am not really explaining myself very well but appreciate the help. I don’t want to color the entire range for say 31 columns wide. The point of the loop was to show you that I want to set a variable and use it for the column number.

    I am going to go column by column and look for a value in a cell in each column, if the test is true then color the three ranges in that column, if false continue through the loop to the next column.
    Last edited by shg; 02-01-2011 at 06:34 PM. Reason: deleted spurious quote

  14. #14
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Highlight noncontiguous ranges of cells

    OK, here you go.

    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    07-25-2008
    Location
    Bend, Oregon
    Posts
    39

    Re: Highlight noncontiguous ranges of cells

    Thanks you so very much and sorry it took so long for me to explain what I was after. That is working perfectly. Here is the code as I modified it for my use and a copy of a test workbook.

    What do you think of my approach, is there a cleaner/better way? Do I need the entire object description “ActiveWorkbook.ActiveSheet.Cells(3, iCol)”? The code will be run from a button on a sheet but the code will be in a module available for use by 12 sheets.

    Please Login or Register  to view this content.
    Attached Files Attached Files

+ 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