我有一张大约10列网格的工作表。工作表中的第11列使用这10列中的数据进行一些计算并保存结果。在最初的10列之间添加新列后,我的范围会发生变化。所以,现在我必须将结果发布在第12列。
object.subObject1 = { numbers: numbers.slice(), letters: letters.slice(), fruits: fruits.slice() };
object.subObject2 = { numbers: numbers.slice(), letters: letters.slice(), fruits: fruits.slice() };
object.subObject1.numbers.push(3);
console.log(object.subObject2.numbers);
这是我更改的现有代码,并增加了列索引。
可悲的是,这不起作用,因为下面的行会引发超出范围的异常。
Private Sub Worksheet_Change(ByVal Target As Range)
' Check if change is made to the correct range of cells.
Dim Results As Variant
'Defaults while sheet only used in Rotterdam
mGravityUnit = UnitDensity
mVolumeUnit = UnitCubicMetres
mTempUnit = UnitCelcius
With Application
If Not (.Intersect(Target, Range("BargeOpenTemp")) Is Nothing And .Intersect(Target, Range("BargeOpenDens")) Is Nothing And .Intersect(Target, Range("BargeCloseTemp")) Is Nothing And .Intersect(Target, Range("BargeCloseDens")) Is Nothing And .Intersect(Target, Range("BargeGrossVolOpen")) Is Nothing And .Intersect(Target, Range("BargeGrossVolClose")) Is Nothing) Then
' Change in Volume Temp or Density
Dim ThisRow As Integer, VCF As Double
ThisRow = Target.Row
If Not (Cells(ThisRow, 3) = "" Or Cells(ThisRow, 11) = "") Then
Results = VCF_Calculation(Cells(ThisRow, 3), mTempUnit, Cells(ThisRow, 11), mGravityUnit, mVolumeUnit)
' Results = VCF_Calc(Cells(ThisRow, 3), Cells(ThisRow, 10), mGravityUnit, 15, 0)
Cells(ThisRow, 12) = Results
'Range("BargeVCFOpen").Value = Results(1)
'Range("BargeVCFClose").Value = Results(1)
Else
Cells(ThisRow, 12) = ""
End If
'If closing reading has already been entered then re-calculate the clocing VCF as theoretical Density may have changed.
If ThisRow < 25 Then
ThisRow = Target.Row + 20
If Not (Cells(ThisRow, 3) = "" Or Cells(ThisRow, 11) = "") Then
Results = VCF_Calculation(Cells(ThisRow, 3), mTempUnit, Cells(ThisRow, 11), mGravityUnit, mVolumeUnit)
' Results = VCF_Calc(Cells(ThisRow, 3), Cells(ThisRow, 10), mGravityUnit, 15, 0)
Cells(ThisRow, 12) = Results
'Range("BargeVCFOpen").Value = Results(1)
'Range("BargeVCFClose").Value = Results(1)
Else
Cells(ThisRow, 12) = ""
End If
End If
End If
End With
End Sub
显然,我必须在excel的某处更新目标。但我似乎无法在任何地方找到相同的东西。
答案 0 :(得分:0)
没关系。找到了如何做这种改变。只需要选择左上角的范围,然后更新单元格编号。