excel - 寻找如何通过循环将用户输入放入我的代码中
问题描述
Sub Delete0()
Dim myRow As Variant
myRow = InputBox("What row does the data start in?")
Dim myColumn As Variant
myColumn = InputBox("What Column does the data start in? (number format, i.e A=1, B=2)")
Dim LR As Long
Dim FR As Long
LR = 1 'where to have myRow be entered
FR = Cells(Rows.Count, 1).End(xlUp).Row
Do Until LR > FR
If Cells(LR, 17).Value > 0 Then 'Where to have myColumn be entered
LR = LR + 1
Else
Cells(LR, 17).EntireRow.Delete
FR = FR - 1
End If
Loop
End Sub
这是我当前的代码,但我想在数据上添加用户输入可能会从不同的行开始每周更改,并且在不同的列中删除值。我如何将其输入到我当前的代码中?
解决方案
鉴于您提供的代码,下面的代码段应该是最简单的方法。我已将 myRow 和 myColumn 的数据类型更改为 Long 以在输入时引发错误。
Sub Delete0()
Dim myRow As Long
myRow = InputBox("What row does the data start in?")
Dim myColumn As Long
myColumn = InputBox("What Column does the data start in? (number format, i.e A=1, B=2)")
Dim LR As Long
Dim FR As Long
LR = myRow 'where to have myRow be entered
FR = Cells(Rows.Count, 1).End(xlUp).Row
Do Until LR > FR
If Cells(LR, myColumn).Value > 0 Then 'Where to have myColumn be entered
LR = LR + 1
Else
Cells(LR, myColumn).EntireRow.Delete
FR = FR - 1
End If
Loop
End Sub
推荐阅读
- python - 关于 sum 函数的 Python 弃用警告
- python - ValueError:超出最大允许尺寸,AgglomerativeClustering fit_predict
- amazon-web-services - AWS Cloudformation 错误:由于递归导入而导致递归锁定
- wordpress - Elementor 插件无法在 localhost 上运行
- python - 消息未显示在管理 django 面板中
- symfony - 实体如何被持久化两次?
- django - Django 无法从 DetailView 更新另一个模型
- sql-server - 如何在 SQL Server 中对多列数据进行排名?
- ios - 如何在 Info.plist 中添加变量值
- regex - Python,使用正则表达式修复日期