How can I Identify Range And Then Last Cell In Range And Insert Absolute Cell Address Into R1C1 Formula?
-
TargetWeight.Address.Row
should beTargetWeight.Row
-
TargetWeight.Address.Column
should beTargetWeight.Column
- When you create an xlR1C1 style address, the n inside
[n]
is a relative row or column adjustment.RC[-1]
means same row, one column left. You want an absolute address and you have absolute row and column as long integers soR" & totalweightr & "C" & totalweightc
-
You don't
Set
integer values, you assign them with an=
. You onlySet
objects like ranges, cells, worksheets, etc.For Each cell In rng2 If cell.Offset(0, -1).Value <> "" Then Set sidewight = cell.Offset(0, -1) Set TargetWeight = sideweight.End(xlDown) TargetWeightr = TargetWeight.Row TargetWeightc = TargetWeight.Column cell.FormulaR1C1 = "=RC[-1]/R" & TargetWeightr & "C" & TargetWeightc End If Next cell
You might also want to forget all of the manipulation and just use TargetWeight.Address in xlR1C1 style.
For Each cell In rng2
If cell.Offset(0, -1).Value <> "" Then
Set sideweight = cell.Offset(0, -1)
Set TargetWeight = sideweight.End(xlDown)
cell.FormulaR1C1 = "=RC[-1]/" & TargetWeight.Address(referencestyle:=xlR1C1)
End If
Next cell