excel - VBA,范围列 + 1
问题描述
我试图在我的范围内将我的列增加一。人们说要使用.Cells
这个,但我得到一个错误。Type mistmatch
. 如何将nameColumn
变量列增加 1?
sh.Range(sh.Cells(lastR1, nameColumn + 1), sh.Cells(lastR1, lastCol)).AutoFill _
Destination:=sh.Range(sh.Cells(lastR1, nameColumn + 1), sh.Cells(lastR, lastCol))
名称列变量:
nameColumn = Split(.Find(Sheets("Input").Range("A2"), .Cells(.Cells.Count), xlValues, _
xlWhole).Address, "$")(1)
解决方案
使用列字母很笨重。您不能添加1
到列字母。
改用列索引:
Dim foundCell As Range
Set foundCell = .Find(Sheets("Input").Range("A2"), .Cells(.Cells.Count), xlValues, xlWhole)
If Not foundCell Is Nothing Then
Dim colNumber As Long
colNumber = foundCell.Column
Else
' not found, throw error or alert user...
End If
然后,您可以轻松地使用列号进行数学运算,即colNumber + 1
.
推荐阅读
- javascript - React Native - 编辑代码推送目标/版本号(在应用程序中)
- intel-mkl - 在运行 macOS Catalina 的 Mac 上构建 Kaldi
- java - Flutter WebView在html选择上崩溃
- c# - C#、SQL 服务器。提供者:TCP 提供者,错误:0 - 不知道这样的主机
- node.js - 将 vue 应用程序部署到 heroku 时出错
- c# - IFormFile 在 ASP.NET Core 3.0 中返回 NULL
- javascript - 我们可以在 Axios 中做一个 If - ReactJS
- python - 属性错误:“ReduceLROnPlateau”对象没有属性 _cmp
- java - Android - 创建自定义 xml 属性,如 onClick?
- ios - 在swift 5中选择下拉菜单后如何隐藏表格单元格?