PSS ID Number: 125267
Article Last Modified on 8/15/2003
Sub SelectEveryNthRow()
' Initialize ColsSelection equal to the number of columns in the
' selection.
ColsSelection = Selection.Columns.Count
' Initialize RowsSelection equal to the number of rows in your
' selection.
RowsSelection = Selection.Rows.Count
' Initialize RowsBetween equal to three.
RowsBetween = 3
' Initialize Diff equal to one row less than the first row number of
' the selection.
Diff = Selection.Row - 1
' Resize the selection to be 1 column wide and the same number of
' rows long as the initial selection.
Selection.Resize(RowsSelection, 1).Select
' Resize the selection to be every third row and the same number of
' columns wide as the original selection.
Set FinalRange = Selection. _
Offset(RowsBetween - 1, 0).Resize(1,ColsSelection)
' Loop through each cell in the selection.
For Each xCell In Selection
' If the row number is a multiple of 3, then . . .
If xCell.Row Mod RowsBetween = Diff Then
' ...reset FinalRange to include the union of the current
' FinalRange and the same number of columns.
Set FinalRange = Application.Union _
(FinalRange, xCell.Resize(1,ColsSelection))
' End check.
End If
' Iterate loop.
Next xCell
' Select the requested cells in the range.
FinalRange.Select
End Sub
For an example of a similar Microsoft Excel 4.0 macro, please see the
following article in the Microsoft Knowledge Base:
103165 Excel: Macro to Select a Range Every nth Row/Column
Additional query words: XL97 XL98 XL7 XL5 XL
Keywords: kbdtacode kbhowto kbProgramming KB125267
Technology: kbExcel500 kbExcel95 kbExcel95Search kbExcel97Search kbExcel98 kbExcel98Search kbExcelMacsearch kbExcelSearch kbExcelWinSearch kbHWMAC kbOSMAC kbVBASearch kbZNotKeyword3 kbZNotKeyword6