I want to create a cell formula which references cells like B1, e.g. ActiveSheet.Cells(1,x).Formula = "=B1*" & x
. However, I want to use the .Cells
function rather than a Range
reference to reference cells.
Given:
Dim x As Integer
Dim y As Integer
x = 5
y = 10
I want this:
ActiveSheet.Cells(1,x).Formula = "=" & ActiveSheet.Cells(y,1) & "*" & x
To provide the same output as:
ActiveSheet.Cells(1,x).Formula = "=B" & y & "*" & x
Ideally, I want to be able to dynamically change both the row and column of the cell I am referencing in the formula. However, I still want the cell to show up as a cell in the formula and not simply the value of the referenced cell.
.Address
- e.g.,ActiveSheet.Cells(y,1).Address(False, False)
. – Chel.Address
works in regards to avoiding getting a formula, but if I use.Address
, will this:ActiveSheet.Cells(1,x).Formula = "=" & ActiveSheet.Cells(y,1).Address(False, False)
give me the same as this:ActiveSheet.Cells(1,x).Formula = "=B" & y & "*" & x
, provided x = 5 and y = 10? – CSAWActiveSheet.Cells(y,1).Address(False, False)
equal to a variable. What object type is it? A range? (I tried to set it to a range and it did not work) – CSAW