Sheets.Range 中的值
Posted
技术标签:
【中文标题】Sheets.Range 中的值【英文标题】:value in Sheets.Range 【发布时间】:2021-12-23 00:40:30 【问题描述】:我是初学者。如何在 Sheets("").Range("").Select 方法中使用值 我的代码如下。
Dim value As String
ThisWorkbook.Sheets("Arkusz1").Range("B2").Select
value = ThisWorkbook.Sheets("Arkusz1").Range("B2").value
Sheets("Welding").Select
Sheets("Welding").Range(value & "50";value & "61").Select
【问题讨论】:
您能否添加更多细节,例如您希望实现的目标,value
可能是列字母?您要选择 2 个单元格还是选择 from 和 to?
将最后一行中的 ;
替换为 :
。
【参考方案1】:
Columns'n'Rows
Option Explicit
Sub ColumnsnRows()
Dim wb As Workbook: Set wb = ThisWorkbook ' workbook containing this code
Dim sws As Worksheet: Set sws = wb.Worksheets("Arkusz1")
Dim sCell As Range: Set sCell = sws.Range("B2")
Dim dws As Worksheet: Set dws = wb.Worksheets("Welding")
Dim dCol As String: dCol = sCell.value
Dim drg As Range: Set drg = dws.Rows("50:61").Columns(dCol)
' You probably meant to use:
'Set drg = dws.Range(dCol & "50:" & dCol & "61")
' Continue using 'drg'...
' You usually don't need to select, but if you do, you have to make sure
' that the worksheet is active.
If Not dws Is ActiveSheet Then
dws.Activate
End If
drg.Select
' Print the address in the Immediate window ('Ctrl+G'):
'Debug.Print drg.Address
' Or:
'drg.Interior.Color = vbYellow
'drg.Font.Bold = True
'drg.Copy
End Sub
【讨论】:
以上是关于Sheets.Range 中的值的主要内容,如果未能解决你的问题,请参考以下文章