+ Reply to Thread
Results 1 to 10 of 10

VBA multi row highlight issue

  1. #1
    Registered User
    Join Date
    04-26-2013
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    5

    VBA multi row highlight issue

    Hello,

    I am working in Access to export a query to Excel. The number of records varies depending on the parameters selected. If there are more than 1000 records I would like to highlight alternating blocks of 1000 records. I sort of have it working, but not quite the way I would like it. Although I understand the problem, my VBA skills aren't particularly great and I'm having trouble figuring out how to fix my issue.

    The problem is that the last block is unlikely to have exactly 1000 records in it, but it's set to highlight 1000 so I need it to look at the selection and only highlight the number of filled cells. The second is that because it alternates colours it also continues 1 block of 1000 past empty cells.

    Any help is greatly appreciated!!


    ----------------------



    Please Login or Register  to view this content.
    Last edited by arlu1201; 07-01-2013 at 01:56 AM. Reason: Use code tags in future.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA multi row highlight issue

    Maybe:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    04-26-2013
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: VBA multi row highlight issue

    This looks promising thanks! Although I'm getting a "Compile error: Loop without Do"

    Any thoughts?

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA multi row highlight issue

    Hi Flower,

    I forgot to write Next for the For Loops:

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    04-26-2013
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: VBA multi row highlight issue

    That seems to solve the compile error but unfortunately the output isn't right. I'm working just in an excel sheet right now rather than from access just to make it easier to get things working. I put different colors and lowered it to blocks of 10 just to see what's happening. It seems to highlight the first 10 as it should but then it highlights line 4 with colourindex 7? And then nothing else happens.

    This is the code as it stands now:



    Dim i As Integer

    Range("A1:C1").Select

    Do Until IsEmpty(ActiveCell.Offset(1, 0))
    ActiveCell.Range("A2:C" & 10).Interior.ColorIndex = 15

    For i = 0 To 9
    If Cells(ActiveCell.Row + i) = "" Then
    ActiveCell.Range("A1:C1").Offset(i, 0).Select
    Selection.Interior.ColorIndex = 7: Exit Do: End If
    Next i
    ActiveCell.Range("A1:C1").Offset(10, 0).Select
    Selection.Resize(1000, 1).Select
    Selection.Interior.ColorIndex = 6

    For i = 0 To 9
    If Cells(ActiveCell.Row + i) = "" Then
    ActiveCell.Range("A1:C1").Offset(i, 0).Select
    Selection.Interior.ColorIndex = 12: Exit Do: End If
    Next i
    ActiveCell.Range("A1:C1").Offset(10, 0).Select
    Selection.Resize(10, 1).Select
    Selection.Interior.ColorIndex = 16

    Loop

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA multi row highlight issue

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

  7. #7
    Registered User
    Join Date
    04-26-2013
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: VBA multi row highlight issue

    I forgot to change that one to 10 as well Still doesn't change the output though

    I don't think it likes the first if statement (below) as it highlights in that color no matter if it is filled or not. And it's filled so it shouldn't be highlighting in that color. It's also not looping so must be exiting.

    If Cells(ActiveCell.Row + i) = "" Then

  8. #8
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA multi row highlight issue

    Hi Flower,

    Maybe:

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    04-26-2013
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: VBA multi row highlight issue

    Ultimately I reworked it and used countA which seemed to work for me. Here is my final code. Thanks for the help!


    Please Login or Register  to view this content.
    Last edited by arlu1201; 07-01-2013 at 01:56 AM. Reason: Use code tags in future.

  10. #10
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA multi row highlight issue

    You're welcome!

+ 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