跳到主要内容

如何在Excel中选择每隔一行或第n行?

有时,当我们使用工作表时,我们需要选择工作表的每隔一行或第n行以进行格式化,删除或复制。 您可以手动选择它们,但是如果有数百行,则此方法不是一个好的选择。 这里有一些技巧可以帮助您。

使用VBA选择每隔一行或第n行

使用 Kutools for Excel 选择每隔一行或第 n 行好主意3


使用VBA选择每隔一行或第n行

在此示例中,我将选择两个间隔的一行。 使用VBA代码,可以完成以下操作:

1.突出显示要每隔一行或第n行选择的范围。

2.Click 开发商 > Visual Basic中,一个新的 适用于应用程序的Microsoft Visual Basic 将显示一个窗口,单击 插页 > 模块,然后将以下代码输入到模块中:

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.然后点击 文档乘法计算 3 按钮运行代码。 并弹出一个对话框供您选择范围。 看截图:



4。 点击 OK,在这种情况下,我在另一个弹出对话框中输入3作为间隔行。 看截图

5。 点击 OK,并选择了每三行。 看截图:

您可以根据需要更改间隔 KutoolsForexcel. 对话。


使用 Kutools for Excel 选择每隔一行或第 n 行

使用VBA代码,您只能选择具有指定间隔的一行,如果您需要选择具有指定间隔的两,三或其他行,则 Kutools for Excel 可以帮助您轻松方便地解决此问题。

Kutools for Excel, 与超过 300 方便的功能,使您的工作更加轻松。 

免费安装 Kutools for Excel,请执行以下操作:

1。 点击 库工具 > Select > Select Interval Rows & Columns…,请参见屏幕截图:

doc每隔一行选择8

2.在  Select Interval Rows & Columns 对话框,单击文档替换范围名称 7 按钮选择所需范围,然后选择 Rows or ColumnsSelect 部分,然后在 Interval of 输入框和 Rows 输入框。 看截图:

doc每隔一行选择9

doc每隔一行选择10

笔记:
1.如果您需要选择选择项中的每隔一行,请在“输入间隔”框中输入2,在“输入间隔”中输入1。 Rows 输入框。

2.如果要选择所需的整个行,可以检查 Select entire rows 选项。
doc每隔一行选择11


使用 Kutools for Excel 每隔一行或第 n 行着色

如果您想在每隔一行阴影范围,以使数据看起来更加出色,如下面的屏幕截图所示,则可以应用 Kutools for ExcelAlternate Row/Column Shading 功能以快速处理工作。

doc每隔一行选择12
doc向下箭头
doc每隔一行选择13

免费安装 Kutools for Excel,请执行以下操作:

1.选择要间隔阴影的单元格范围,单击 库工具 > Format > Alternate Row/Column Shading.
doc每隔一行选择14

2.在 Alternate Row/Column Shading 对话框中,请执行以下操作:

1)选择要着色的行或列;

2)选择 Conditional formatting or 标准格式 根据需要

3)指定阴影间隔;

4)选择阴影颜色。
doc每隔一行选择15

3。 点击 Ok。 现在,该范围已在第n行中加阴影。

如果要删除阴影,请检查 删除现有的备用行底纹 选项 交替的行/列底纹 对话。


相关文章:

最佳办公生产力工具

🤖 Kutools 人工智能助手:基于以下内容彻底改变数据分析: 智能执行   |  生成代码  |  创建自定义公式  |  分析数据并生成图表  |  调用 Kutools 函数...
热门特色: 查找、突出显示或识别重复项   |  删除空白行   |  合并列或单元格而不丢失数据   |   不使用公式进行四舍五入 ...
超级查询: 多条件VLookup    多值VLookup  |   跨多个工作表的 VLookup   |   模糊查询 ....
高级下拉列表: 快速创建下拉列表   |  依赖下拉列表   |  多选下拉列表 ....
列管理器: 添加特定数量的列  |  移动列  |  切换隐藏列的可见性状态  |  比较范围和列 ...
特色功能: 网格焦点   |  设计图   |   大方程式酒吧    工作簿和工作表管理器   |  资源库 (自动文本)   |  日期选择器   |  合并工作表   |  加密/解密单元格    按列表发送电子邮件   |  超级筛选   |   特殊过滤器 (过滤粗体/斜体/删除线...)...
前 15 个工具集12 文本 工具 (添加文本, 删除字符,...)   |   50+ 图表 类型 (甘特图,...)   |   40+ 实用 公式 (根据生日计算年龄,...)   |   19 插入 工具 (插入二维码, 从路径插入图片,...)   |   12 转化 工具 (小写金额转大写, 货币兑换,...)   |   7 合并与拆分 工具 (高级组合行, 分裂细胞,...)   |   ... 和更多

使用 Kutools for Excel 增强您的 Excel 技能,体验前所未有的效率。 Kutools for Excel 提供了 300 多种高级功能来提高生产力并节省时间。  单击此处获取您最需要的功能...

产品描述


Office Tab 为 Office 带来选项卡式界面,让您的工作更加轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
  • 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
  • 每天将您的工作效率提高50%,并减少数百次鼠标单击!
Comments (12)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Help, 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".
This comment was minimized by the moderator on the site
Also I don't get how "Set" and "Step" could ever work together
This comment was minimized by the moderator on the site
Not 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.
This comment was minimized by the moderator on the site
Replace OutRng.EntireRow.Select with Intersect(OutRng.EntireRow, InputRng).Select if you want every other row within your selection
This comment was minimized by the moderator on the site
really good, thanks!
This comment was minimized by the moderator on the site
The 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.
This comment was minimized by the moderator on the site
I made the modifications below to select 30 rows 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).Resize(, 30) 'Resize to the number of columns to select, 30 in this case If OutRng Is Nothing Then Set OutRng = rng Else Set OutRng = Application.Union(OutRng, rng) End If Next OutRng.Select 'Use OutRng.EntireRow.Select to select the entire row End Sub
This comment was minimized by the moderator on the site
Nice, thanks, this was very helpful ^_^
This comment was minimized by the moderator on the site
fanatastic. 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.
This comment was minimized by the moderator on the site
I'm trying to use the VBA macro in Excel 2010. It will only select the first nth row, not all of them in the selection. If I run it again, it will go to the next. Any idea what I'm doing wrong? Thanks!
This comment was minimized by the moderator on the site
Just saved my ass with this code thanks! My matlab decided to randomly stop working and so I had to resort to excel which I am not as familiar with as with Matlab. This def. helped. Thanks.
This comment was minimized by the moderator on the site
I need to select multiple rows and a fixed interval and move to the other sheet please answer me as soon as possible 
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations