以下はVBAで有効です
Range("K1:K5")
以下が有効でないのはなぜですか?
Dim nb As Long
Range("K1:K" + nb)
Range("K1:K" & nb) も試し、String
代わりに nb a を作ってみました。
の値nb = 0
とExcelの行はで始まるため1
これを試して
Dim nb As Long
Dim Rng As Range
nb = 2
Set Rng = Range("K1:K" & nb)
nb の値が何かわかりません。
RowIndex と ColumnIndex が整数である Cells(RowIndex, ColumnIndex) 表記を使用してみてください。
Sub RangeExemple()
Dim colIndex, colIndex2, rowIndex, rowIndex2 As Integer
colIndex = 7
colIndex2 = colIndex
rowIndex = 1
rowIndex2 = 5
Range(Cells(rowIndex, colIndex), Cells(rowIndex2, colIndex2)).Interior.ColorIndex = 37
サブ終了
本当は何がしたいの?