excel - 如何在 Excel VBA 中的 .Range 中使用字符串?
问题描述
我需要你的帮助来解决我遇到的问题。
基本上我想做一个变量iRow,通过找到一个具有值OBRC
的单元格,具有这个值的单元格由命令检索find
,然后我从行中获取值并将其视为一个字符串操作字符串以仅获取行号作为出口,直到这部分没什么大不了的。但是当我需要将此字符串变量CellString
用作范围值的一部分时,它不起作用。
我需要这个来使我的脚本工作,因为我需要这个值来在电子表格上写入信息,所以我想知道如何解决它?我正在考虑将此字符串转换为双精度,但我不知道该怎么做。
这是我的代码:
Function FindCell()
Dim CellLocation As Range
Dim CellString As String
Set CellLocation = Sheets("Sheet1").Range("A1048576").Find("OBRC") ' retrieves the value OBRC + the row.
CellString = Right(CellLocation.Text, 0) ' Manipulate the entire value OBEC + Row and retrieves only the row.
With ThisWorkbook.Sheets("Sheet1")
.Range("A" & CellString).Value = "Teste" 'it concatenate the Column + the row, it should be working but is not
End With
End Function
随意给我任何建议。
解决方案
见注释:
Function FindCell()
Dim CellLocation As Range
Set CellLocation = Sheets("Sheet1").Range("A:A").Find("OBRC") 'Returns the cell in which OBRC is found
If Not CellLocation Is Nothing Then
Dim CellString As Long
CellString = CellLocation.Row 'Get the Row.
With ThisWorkbook.Sheets("Sheet1")
.Range("A" & CellString).Value = "Teste"
End With
End If
End Function
我将其保留为函数,但如果不打算将值返回给外部源,那么这应该是Sub()
推荐阅读
- angular - 垫子步进完成图标不在圆圈内
- ruby-on-rails - 如何使用 Sortable.js、acts_as_list 和 Stimulus 为nested_attributes 获得正确的位置
- r - 优化在数据帧的多个列中查找案例和控件之间最短距离的过程
- node.js - 模型产品上的属性“类别”和关联“类别”之间的命名冲突
- flutter - 跟踪我的全局 dart 变量的最佳方法(我可以重新分配和读取)
- ag-grid - 展开和关闭图标将始终自动出现在组列中,虽然我没有设置 columnGroupShow
- java - 实体类的两个hashmap
- spring - 配置 spring boot 以重定向某些 url 上的某些错误
- c++ - 概念示例的简单 C++ 接口
- selenium-webdriver - 将列表的值拖放到页面的随机区域,不起作用