我正在尝试使用Excel VBA创建一个Range变量,该变量位于sourcerange
右侧的一列。
Dim targetRange as Range
Dim sourcerange as range
Set sourceRange = range("B1:B2") 'Works
Set targetRange = Range(cells(sourceRange.row, sourceRange.Column + 1)) 'does not work
Set targetRange = Range(Cells(2, 2)) 'does not work
任何人都可以帮助解释它为什么不起作用吗?
答案 0 :(得分:4)
使用
val_loss: 0.6811
val_loss: 0.6941
val_loss: 0.6532
val_loss: 0.6546
val_loss: 0.6534
val_loss: 0.6489
val_loss: 0.6240
val_loss: 0.6285
val_loss: 0.6144
val_loss: 0.5921
val_loss: 0.5731
val_loss: 0.5956
val_loss: 0.5753
val_loss: 0.5977
答案 1 :(得分:0)
你的意思是这样吗?
Dim sourceColumn As Long
Dim firstRow As Long
Dim lastRow As Long
Dim sourceRange As Range
Dim targetRange As Range
'Set source column number, and first + last row
sourceColumn = 2
firstRow = 1
lastRow = 3
'Set the source range, using the variables
Set sourceRange = Range(Cells(firstRow, sourceColumn), Cells(lastRow, sourceColumn))
'Likewise, set the target range, but using column number + 1
Set targetRange = Range(Cells(firstRow, sourceColumn + 1), Cells(lastRow, sourceColumn + 1))