如何将地址转换回VBA范围?
我有一个输入框,要求用户选择一个单元格,将其存储为一个范围。 然后,此范围将转换为地址(字符串),因此!工作表也没有保存。
a for循环将循环浏览工作表,但是,我需要引用启动单元格(范围)以运行宏 - 问题是,我不能再引用启动单元格,因为这现在是字符串,而不是范围。
我需要在for循环中重新将地址(字符串)重新转换回范围。
Set myCell = Application.InputBox( _
prompt:="Select a cell", Type:=8)
celladdress = myCell.Address()
NoSheets = Sheets.Count
For x = 2 To NoSheets
'covert address back to range
'Identify blend data
NumRows = Range(myCell, myCell.Offset(1, 0).End(xlDown)).Rows.Count
NumColumns = Range(myCell, myCell.Offset(0, 1).End(xlToRight)).Columns.Count
Set StartRange = Range(myCell, myCell.Offset(NumRows - 1, NumColumns - 1))
StartRange.Copy
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要一个
工作表
该循环中的对象引用:一旦有了工作表,您仍然可以使用
mycell
在range > Currentsheet ,不处理单元格字符串:
避免访问
range> range>
和cells
;它们隐含地指的是ActivesHeet
,这通常意味着仅适用于worksheet.activate 呼叫(您通常希望避免使用
select select)
和激活
完全)。You want a
Worksheet
object reference inside that loop:Once you have the sheet, you can still use
myCell
to get aRange
on thecurrentSheet
, without dealing with cell address strings:Avoid unqualified calls to
Range
andCells
; they're implicitly referring to theActiveSheet
, which typically means code that only works withWorksheet.Activate
calls sprinkled through (you generally want to avoid having to useSelect
andActivate
altogether).mycell.address(true)为您提供范围的完整外部地址。
mycell.parent.name给您工作表的名称
myCell.address(,,,true) gives you the full external address of the range.
myCell.Parent.Name gives you the name of the worksheet