vba - VBA动态循环填充列
问题描述
我正在尝试用 1 从标题后的第二行到最后一行填充列的每一行。在名为 Adults 的工作表中,该列是“Ok to call”。此代码在我需要的正确工作表中创建列,但不会用 1 填充行。我相信我必须在最后一行添加但不知道如何添加。感谢任何帮助!
Dim shtA As Worksheet
Set shtA = ActiveWorkbook.Sheets("Adults")
Dim LastCol As Long
LastCol = shtA.Cells(1, Columns.Count).End(xlToLeft).Column
Dim lastRow As Long
lastRow = shtA.Cells(Rows.Count, 1).End(xlUp).Row
'Loop through heading row to get column number of "Ok to call?"
Dim okcall As Long
Dim a As Long
For a = 1 To LastCol
If LCase(shtA.Cells(1, a).Value) = "ok to call?" Then
okcall = a
Exit For
End If
Next a
解决方案
在 PeterT 的建议之后添加了这个:
For a = 1 + 1 To lastRow
shtA.Cells(a, okcall).Value = 1
Next a
End
推荐阅读
- android - 矢量资产android studio的圆角
- arrays - 追加到 pyspark 数组列
- c# - 未在动态对象上设置属性时如何引发特定异常
- windows - MinGW vs MSVS下的Windos导出/导入符号;CMake 的 WINDOWS_EXPORT_ALL_SYMBOLS 被忽略
- php - 函数 App\Http\Controllers\Admin\AccountsController::index() 的参数太少,通过了 0 并且在 laravel 中预期正好 1
- jestjs - .env for jest 和 nest 不一样
- ldap - TDI for HCL Connections 6.5 同步失败并出现“错误的 SQL 语法 [];” 错误
- javascript - 打包使用 node-windows 作为服务运行的 Node.js 应用程序
- arrays - 类验证器不验证数组
- facebook - 在 chrome 扩展中使用 Facebook 消息 API/SDK?