跳到主要内容

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

在处理工作表时,有时可能需要交换两个单元格的内容。 通常,我们大多数人只知道“剪切,粘贴和复制”即可交换内容,但这很耗时。 我们将讨论如何在Excel中快速交换内容。

手动交换两个相邻的单元格内容
用VBA代码交换两个不相邻的单元格内容
只需单击几下即可轻松交换两个随机单元格内容


手动交换两个相邻的单元格内容

有时,需要交换两个相邻的单元格。 我们可以手动轻松地做到这一点。 看下面的屏幕截图,我想交换单元格A4和B4,请执行以下操作:

文档交换单元格1

1。 选择要交换的单元格。 在本示例中,选择单元格A4。

2。 按 转移 键,然后将光标置于右边框。

3。 然后将光标拖到单元格B4的右边界。

4。 当显示“”,松开鼠标。

5。 并且两个单元格内容已交换。 看截图:

文档交换单元格2

使用此方法,我们还可以交换两个相邻的行或列。

在Excel中快速交换两个单元格或范围的内容:

Kutools for Excel's 交换范围 实用程序可帮助您轻松地一次在Excel中交换两个指定的单元格或范围,如下面的演示所示。
立即下载并试用! (30 天免费试用)

交换单元1


用VBA代码交换两个不相邻的单元格内容

当两个单元格不相邻时,上述方法将不起作用。 我们可以将它们替换为VBA代码。

1。 按 按Ctrl 键,然后选择要交换的两个不相邻的单元格。

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

Sub SwapTwoRange()
'Updateby20131120
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。 然后点击 文档乘法计算 3 按钮运行代码,然后显示一个对话框供您选择要在其间交换的两个单元格。 查看屏幕截图:

文档交换范围1

4。 点击 Ok 在弹出的对话框中,两个选定的单元被交换。 查看屏幕截图:

文档交换范围1

笔记: 此VBA代码无法交换两个单元格的格式。


只需单击几下即可轻松交换两个随机单元格内容

Kutools for Excel's 交换范围 实用程序,我们不仅可以交换两个相邻的单元格,行或列,而且还可以轻松切换两个不相邻的单元格,行或列。

申请前 Kutools for Excel首先下载并安装.

1。 点击 库工具 > 范围 > 交换范围,请参见屏幕截图:

2.在 交换范围 对话框,您需要:

  • (1)点击第一个 文档替换范围名称 7 按钮在 互换范围1 框以选择要交换的单元格。
  • (2)点击第二 文档替换范围名称 7 来自的按钮 互换范围2 框以选择要交换的单元格。
    Tips:您可以在应用功能之前选择两个范围,然后可以看到所选的两个范围分别显示在“交换范围1”和“交换范围2”框中。
  • (3)点击 OK 按钮。

然后,将立即交换两个选定的单元格或范围。 查看屏幕截图:

文档交换范围1

  如果您想免费试用(30天)此实用程序, 请点击下载,然后按照上述步骤进行操作。


演示:使用 Kutools for 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 (12)
Rated 2.5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
The vba is pants because it loses formulas and formatting. It's incredible that Excel has been through like about 25 different versions and STILL doesn't have the facility in it natively to swap two ranges/non-adjacent cells around. Sort it out Microsoft!
Rated 2.5 out of 5
This comment was minimized by the moderator on the site
Legyenszíves Megírni melyik az a müszak gomb.
Köszönöm Üdv Ádám
This comment was minimized by the moderator on the site
this isn't working for me. I don't know why
This comment was minimized by the moderator on the site
Koje njesra... na kraju cu ipak raditi copy paste... Umesto da su ubacili swap opciju na padajucem menju....
This comment was minimized by the moderator on the site
Cool trick that saved me a lot of time. Thank you!
This comment was minimized by the moderator on the site
First option work well for me thanks for your efforts... :-)
This comment was minimized by the moderator on the site
Thanks !! works perfectly for me..
This comment was minimized by the moderator on the site
Thanks !! works perfectly for me..
This comment was minimized by the moderator on the site
Thank you for the information!!!
This comment was minimized by the moderator on the site
You could just cut (non-adjacent) Cell A into an unoccupied cell, paste required cell B into that space then put A into the cell B formerly occupied couldn't you?
This comment was minimized by the moderator on the site
It's not as simple as you suggested when cells have formula in them. And this also helps in inserting multiple cells at any desired location as well.
This comment was minimized by the moderator on the site
Yes you could, but why go such a roundabout way when you can do it much faster this way. Thanks ExtendOffice for your good work.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations