To post as a guest, your comment is unpublished.· 1 years agoAlso I don't get how "Set" and "Step" could ever work together
To post as a guest, your comment is unpublished.· 1 years agoNot sure that I will be able to help, but..
First of, there is a spacing between "C" and "ount" in "Count" when i copied your code string over to a module.
Secondly, I can´t find your code anywhere else on this page, please submit the whole thing, if the problem remains.
How to select every other or nth row in Excel?
When we use a worksheet, sometimes, we need to select the every other or nth row of the sheet for formatting, deleting or copying purpose. You can select them manually, but if there are hundreds of rows, this method is not a good choice. Here are some tricks to help you.
Select every nth rows or columns in Excel Worksheet
|With the Select Interval Rows & Columns utility of Kutools for Excel, you can quickly select every other or nth rows/columns by settiing the references in Interval of and Rows/Columns sections. Free download!|
|Kutools for Excel: with more than 300 handy Excel add-ins, free to try with no limitation in 60 days.|
In this example, I will select one row with two intervals. With VBA code, I can finish it as follows:
1. Highlight the range that you want to select every other or nth row.
2.Click Developer > Visual Basic, a new Microsoft Visual Basic for applications window will be displayed, click Insert > Module, and input the following code into the Module:
Sub EveryOtherRow() Dim rng As Range Dim InputRng As Range Dim OutRng As Range Dim xInterval As Integer xTitleId = "KutoolsforExcel" Set InputRng = Application.Selection Set InputRng = Application.InputBox("Range :", xTitleId, InputRng.Address, Type:=8) xInterval = Application.InputBox("Enter row interval", xTitleId, Type:=1) For i = 1 To InputRng.Rows.Count Step xInterval + 1 Set rng = InputRng.Cells(i, 1) If OutRng Is Nothing Then Set OutRng = rng Else Set OutRng = Application.Union(OutRng, rng) End If Next OutRng.EntireRow.Select End Sub
3.Then click button to run the code. And a dialog pops up for you to select a range. See screenshot:
4. Click OK, and in this case, I input 3 in the another pop out dialog as the interval row. See screenshot
5. Click OK, and the every third row has been selected. See screenshot:
You can change the interval as you need in the second KutoolsforExcel dialog.
With VBA code, you can only select one row with specified intervals, if you need to select two, three or other rows with specified intervals, the Kutools for Excel can help you solve this problem easily and conveniently.
|Kutools for Excel, with more than 300 handy functions, makes your jobs more easier.|
After free installing Kutools for Excel, please do as below:
1. Click Kutools > Select > Select Interval Rows & Columns…,see screenshot:
2. In the Select Interval Rows & Columns dialog box, click button to select the range you need, choose Rows or Columns from Select section, and specify the number you want in the Interval of input box and Rows input box. See screenshot:
1. If you need to select every other row in the selection, please enter 2 in the Intervals of Input box and 1 in the Rows input box.
2. If you want to select the entire row that you need, you can check Select entire rows option.
If you want to shade ranges in every other row so that the data looks more outstanding as below screenshot shown, you can apply Kutools for Excel’s Alternate Row/Column Shading function to quickly handle the job.
After free installing Kutools for Excel, please do as below:
1. Select the range of cells you want to interval shade, click Kutools > Format > Alternate Row/Column Shading.
2. In the Alternate Row/Column Shading dialog, do as these:
1)Select the rows or columns you want to shade;
2)Choose Conditional formatting or standard formatting as you need;
3)Specify shading interval;
4)Choose a shading color.
3. Click Ok. Now the range has been shaded in every nth row.
If you want to remove the shading, check Remove existing alternate row shading option in Alternate Row/Column Shading dialog.
Tabbed browsing & editing multiple Excel workbooks/Word documents as Firefox, Chrome, Internet Explore 10!
You may be familiar to view multiple webpages in Firefox/Chrome/IE, and switch between them by clicking corresponding tabs easily. Here, Office Tab supports similar processing, which allow you to browse multiple Excel workbooks or Word documents in one Excel window or Word window, and easily switch between them by clicking their tabs. Click for free 45-day trial of Office Tab!
Recommended Productivity Tools
Bring handy tabs to Excel and other Office software, just like Chrome, Firefox and new Internet Explorer.
Amazing! Increase your productivity in 5 minutes. Don't need any special skills, save two hours every day!
300 New Features for Excel, Make Excel Much Easy and Powerful:
- Merge Cell/Rows/Columns without Losing Data.
- Combine and Consolidate Multiple Sheets and Workbooks.
- Compare Ranges, Copy Multiple Ranges, Convert Text to Date, Unit and Currency Conversion.
- Count by Colors, Paging Subtotals, Advanced Sort and Super Filter,
- More Select/Insert/Delete/Text/Format/Link/Comment/Workbooks/Worksheets Tools...
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
To post as a guest, your comment is unpublished.· 1 years agoHelp, please. This looks great, BUT when I hit the > Run button it fails with a "Compile error: Sub or Function not defined" and the code stopped at "Set rng = InputRng.Rows.Count Step xInterval +1".
To post as a guest, your comment is unpublished.· 1 years agoReplace
if you want every other row within your selection
To post as a guest, your comment is unpublished.· 2 years agoreally good, thanks!
To post as a guest, your comment is unpublished.· 3 years agoThe code has one request. Does it have to select the ENTIRE ROW for each nth row? Can't it just select certain cells (range of cells) within each nth row?
I don't need all the information in each row. Just certain cells of each nth row.
To post as a guest, your comment is unpublished.· 2 years agoI made the modifications below to select 30 rows
Dim rng As Range
Dim InputRng As Range
Dim OutRng As Range
Dim xInterval As Integer
xTitleId = "KutoolsforExcel"
Set InputRng = Application.Selection
Set InputRng = Application.InputBox("Range :", xTitleId, InputRng.Address, Type:=8)
xInterval = Application.InputBox("Enter row interval", xTitleId, Type:=1)
For i = 1 To InputRng.Rows.Count Step xInterval + 1
Set rng = InputRng.Cells(i, 1).Resize(, 30) 'Resize to the number of columns to select, 30 in this case
If OutRng Is Nothing Then
Set OutRng = rng
Set OutRng = Application.Union(OutRng, rng)
OutRng.Select 'Use OutRng.EntireRow.Select to select the entire row
To post as a guest, your comment is unpublished.· 3 years agofanatastic.
thanks a lot.it works perfect.I have more than 7000 data that need to select them with different interval.this trick was like a miracle for me.thaaaaaaaanks.