excel - 根据给定列的值选择 Microsoft Excel 中的单元格
问题描述
首先,我是VBA的完全新手,我的以下考虑是基于我对该主题的搜索
这是我的问题:我需要为每一行删除以紫色表示的单元格数量。我正在尝试编写一个小型 VBA 脚本,让我可以自动执行此操作。由于这个范围是连续的(我必须删除从 F 列到右侧的所有单元格),我知道使用 VBA,我可以使用Range().Select
理想情况下,我认为工作流程是这样的:
for each line in {2,N}
do
fcol = 6 + "$EN" # "$EN" means the value of the cell located in fixed column E, N line; fcol is the final column number
Range(6,N:fcol,N).Select # from six column (F) to end column, "fcol"
enddo
但我不知道如何在 VBA 中实现它:| 任何帮助都将受到欢迎!
解决方案
试试这个
Sub test()
Dim cel As Range
For Each cel In Range("E2", Cells(Rows.Count, 5).End(xlUp))
If cel.Value > 0 Then cel.Offset(, 1).Resize(, cel.Value).ClearContents ' this will delete cell content only
If cel.Value > 0 Then cel.Offset(, 1).Resize(, cel.Value).Delete xlToLeft ' this will delete cells and shifting left those at the right of deleted ones
Next
End Sub
只需根据我留下的评论删除您不需要的行
推荐阅读
- swift - 尝试搜索 Firestore 并重新加载 tableview 时出现 SearchBar 问题
- reactjs - 使用自定义 webpack 配置集成 webpack 和 wix-stylable
- android - 分页时出现越界异常
- javascript - 不同语言的特殊字符验证
- ruby-on-rails - Rails ActiveRecord,用户 ID 获取数据表列表
- perl - Mastodon::Listener: 1 at /home/sergio/perl5/lib/perl5/Role/EventEmitter.pm 第 21 行
- jquery - 在 ASP.NET MVC 中使用具有自动完成功能的处理程序
- delphi - MDI-Form 忽略 StyleElements seClient
- amazon-web-services - 在 Kubernetes 中从不同云提供商的现有集群中添加节点时出现问题?
- javascript - 在循环中附加对象