Results 1 to 5 of 5

Macro to highlight every other row (regardless of range location)

Threaded View

  1. #1
    Registered User
    Join Date
    11-14-2013
    Location
    Idaho
    MS-Off Ver
    Excel 2003
    Posts
    7

    Macro to highlight every other row (regardless of range location)

    I'm currently using:

    Sub SelectEveryNthRow()
    ColsSelection = Selection.Columns.Count
    RowsSelection = Selection.Rows.Count
    RowsBetween = 2
    Diff = Selection.Row - 1
    Selection.Resize(RowsSelection, 1).Select
    Set FinalRange = Selection. _
    Offset(RowsBetween - 1, 0).Resize(1, ColsSelection)
    For Each xCell In Selection
     If xCell.Row Mod RowsBetween = Diff Then
    Set FinalRange = Application.Union _
    (FinalRange, xCell.Resize(1, ColsSelection))
     End If
     Next xCell
     FinalRange.Select
    End Sub
    ...but I find it only works if the first row is within the same number of rows specified in RowsBetween.

    For example, if RowsBetween = 2, and I select a range where the top row is greater than or equal to 3, it will not work properly, but instead select only one row; the row directly under the first row is selected in the desired range; the column count highlighted would be correct; just not the desired range of rows. Any ideas?
    Last edited by alansidman; 02-24-2016 at 12:59 PM. Reason: code tags added

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] macro to compare a range with a standard range and highlight cells, when not matched
    By excelhelpseeker in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 11-27-2014, 12:46 PM
  2. [SOLVED] VBA Macro to copy a range of cells and paste to a new location
    By JuneTwentyFourteen in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-20-2014, 10:38 AM
  3. macro to copy range hidden paste in a specific location
    By graiggoriz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-26-2014, 11:27 AM
  4. [SOLVED] How to highlight a range in a macro without replacing it with a range name such as C1:L15
    By Mary Mullen in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-20-2014, 04:14 PM
  5. Replies: 1
    Last Post: 08-18-2013, 05:00 PM
  6. [SOLVED] macro to 'save as pdf' that prompts for filename, location AND only prints specified range
    By mtcolombo in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-06-2013, 01:49 PM
  7. [SOLVED] Highlight range of cells - run macro - select last cell in range
    By chromachem in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-24-2012, 11:46 AM

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