I have a workbook where I want to reference a range in the first Sheet (B1) for the input of a formula in a cell in the second Sheet (B3). My problem is the first Sheet's name will always change so I thought to get around this I would create a variable based on the cell reference that the formula could use. This is what I have so far:
Sub GetCellAddress()
Dim Cell As Range
Dim CellAddress As String
Set Cell = ActiveWorkbook.Worksheets(1).Cells(1, 2)
CellAddress = Cell.Parent.Name & "!" & Cell.Address(External:=False)
With ActiveSheet
Range("B3").Select
ActiveCell.Formula = _
"=CONCATENATE(""Balance Sheet"","" - "",MID(CellAddress,FIND("" "",CellAddress,FIND("","",CellAddress)+2)+1,256))"
End With
'MsgBox CellAddress
End Sub
Although the MsgBox will confirm the CellAddress I have is Sheet1!$B1$1 I cannot seem to pass this reference in the formula by just using CellAddress as I get the #NAME? error when I use it. If I use Sheet1!R[-2]C as the ActiveCell.FormulaR1C1 syntax, it works fine but as I explained before I want the code to resolve the Sheet name. Either I have the wrong syntax or maybe my method is the incorrect way of referencing a range in another sheet. Can anyone show me where I am going wrong.
,
) in a cell address, external or otherwise. - user4039065