答案 0 :(得分:1)
从您的帖子中很难理解,根据您所附的屏幕截图,我猜测可能是以下代码:
Option Explicit
Sub DynamicSelect()
Dim LastRow As Long, NumofColumns As Long
Dim Rng As Range
LastRow = Cells(Rows.Count, "H").End(xlUp).Row
NumofColumns = Range("L2").Value
' set the range object
Set Rng = Range("H1", Range("H1").Offset(LastRow - 1, NumofColumns))
' if you must Select (not recommended)
Rng.Select
End Sub
答案 1 :(得分:0)
您可以这样做
Sub rangeselect()
n = Cells(2, 12)
Dim rng As Range
Dim Str As String
Str = "H1:H" & n
Set rng = Range(Str)
rng.Select
End Sub