跳到主要内容

如何在Excel中的行或列之间交换内容?

有时,当我们使用工作表时,我们需要交换行或列。 例如,我想将A列与D列交换,想到的第一件事是使用复制和粘贴命令。 实际上,除了复制和粘贴外,还有其他一些方法可以解决此问题。

使用VBA代码交换行或列

使用 Kutools for Excel 快速方便地交换行或列

使用 Kutools for Excel 将数据从行转置为多列


1。 按住 ALT + F11 键,然后打开 Microsoft Visual Basic应用程序 窗口。

2。 点击 插页 > 模块,然后将以下代码粘贴到 模块 窗口。

Sub SwapTwoRange()
'Updateby Extendoffice
Dim Rng1 As Range, Rng2 As Range
Dim arr1 As Variant, arr2 As Variant
xTitleId = "KutoolsforExcel"
Set Rng1 = Application.Selection
Set Rng1 = Application.InputBox("Range1:", xTitleId, Rng1.Address, Type:=8)
Set Rng2 = Application.InputBox("Range2:", xTitleId, Type:=8)
Application.ScreenUpdating = False
arr1 = Rng1.Value
arr2 = Rng2.Value
Rng1.Value = arr2
Rng2.Value = arr1
Application.ScreenUpdating = True
End Sub

3。 然后点击 按钮运行代码,会弹出一个对话框,供您选择要交换的两个范围,请参见屏幕截图:

doc交换行列01 01
1
doc交换行列02 02

4。 点击后 Ok,两个范围被交换。 查看屏幕截图:

doc交换行列01 01 2 doc交换行列02 02

对于Excel初学者来说,这些代码可能有点困难,有没有一种简单的方法可以快速且节省时间。当然,Kutools for Excel 可以帮助您快速轻松地交换行或列。

Kutools for Excel : 带有300多个便捷的Excel加载项,可以在30天内免费试用

如果你已经安装 Kutools for Excel,您可以快速交换两列或两行。

1. 点击 库工具 > 范围 > 互换范围,请看截图:

2.交换范围 对话框,单击  来自的按钮 互换范围1 选择要交换的列A,然后单击  来自的按钮 互换范围2 选择列D.( 注意:交换范围的大小必须相同。)

doc交换行列02 02

3。 然后点击 OK。 两列已被交换,单元格格式也被交换。 查看屏幕截图:

doc交换行列01 01 2 doc交换行列02 02

有了这个 交换范围的实用程序,您不仅可以交换行或列,还可以交换两个范围的内容。 单击此处了解有关此功能的更多信息.

立即下载和免费试用Excel的Kutools!



在Excel工作表中快速将数据从行转移到多列:

Kutools for Excel变换范围 功能,您可以快速将数据从一行或一列转置为多行或一列,反之亦然。

doc转置数据

Kutools for Excel:具有300多个方便的Excel加载项,可以在30天内免费试用,没有任何限制。 立即下载并免费试用!


Kutools for Excel:具有300多个方便的Excel加载项,可以在30天内免费试用,没有任何限制。 立即下载并免费试用!

相关文章:

如何快速交换Excel中两个单元格的内容?

最佳办公生产力工具

🤖 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 (7)
Rated 5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
EXCELENTE, ni me perdí, gracias por su aporte
Rated 5 out of 5
This comment was minimized by the moderator on the site
Okk is there any way we can create a MACRO for it to do it fast bcz it won't be possible everytime to copy that code from somewhere and put it out there to Swap that Rows and Columns .
This comment was minimized by the moderator on the site
or you can just hold the shift key and drag the column where you want it to go
This comment was minimized by the moderator on the site
I've tried the VBA code solution. It seemed to work fine until now. In the range i swap, there is a URL cell (i.e. hyperlink). Although the swap looks ok, the hyperlinks are not updated. It still points to the URL of the original range. Is there any code patch to handle this? thank you.
This comment was minimized by the moderator on the site
Learn how to spell. Ridiculous. Emial. Really?
This comment was minimized by the moderator on the site
Please learn how to spell before posting on the web.
This comment was minimized by the moderator on the site
So in short, there is no built-in way to swap columns. Fail :)
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations