excel - VBA将字母表中的列值转换为数字
问题描述
如何将 excel 地址“$C$2”的 alpha 部分转换为 3 和 2,以便可以在单元格对象中重新使用它。
如果它是“$E$4”,那么我需要两个单独的值,比如 5(对于字母 E)和 4,这样我就可以使用对象来引用它 - Cells(4,5)
基本上,我正在尝试使用下面的代码取消合并单元格,这就是需要获取 excel 单元格数字的地方。
Sub UnMerge()
Dim i As Integer
Dim fromRange() As String
Dim toRange() As String
Dim temp() As String
ActiveSheet.UsedRange.MergeCells = False
fromRange() = Split(ActiveCell.Address, "$")
temp() = Split(Selection.Address, ":")
toRange() = Split(temp(1), "$")
For i = fromRange(2) To toRange(2)
If Cells(i, Range(temp(0)).Column) = "" Then
Cells(i, Range(temp(0)).Column) = Cells(i - 1, Range(temp(0)).Column).Value
End If
Next i
End Sub
解决方案
更改和拆分字符串以获取数字很慢。只需使用 selection.rows 和 selection.column:
Sub UnMerge()
Selection.MergeCells = False
With ActiveSheet
Dim i As Long
For i = Selection.Row To Selection.Rows.Count + Selection.Row - 1
If .Cells(i, Selection.Column) = "" Then
.Cells(i, Selection.Column) = .Cells(i - 1, Selection.Column).Value
End If
Next i
End With
End Sub
推荐阅读
- html - 使用 css 将外部笔画添加到文本中
- javascript - 使用递归检查元素是否为数组
- ruby-on-rails - Symbol 与 100 的比较失败
- date - 如何找到前几周的日期?
- r - 删除R中表格中的重复日期
- kubernetes - 有没有办法检测 Helm Chart 部署的资源所做的更改
- android - 如何区分多个用户的指纹?
- amazon-web-services - AWS CodeArtifact:mvn deploy:deploy-file 无法部署工件:无法传输工件 401 Unauthorized
- c++ - cpp-httplib https 服务器无法在 Linux 上运行
- pyspark - 将列传递给函数,其中列可以为空