siobhan86
12-31-2019, 09:39 AM
Hi, I am trying to make a cell equal to a formula in VBA using a variable for part of the range. I've tried the following two ways to do it and both fail.
Range("H" & endsal + 2).Select
Dim lastsal As String
lastsal = Selection.Address
MsgBox (lastsal)
ActiveCell.Formula = "=AVERAGE(H21:& lastsal)"
AND
Range("H" & endsal + 2).Select
Dim lastsal As String
lastsal = Selection.Address
MsgBox (lastsal)
ActiveCell.Formula = "=AVERAGE(H21:"& lastsal ")"
Can you help me in getting this to work?
Range("H" & endsal + 2).Select
Dim lastsal As String
lastsal = Selection.Address
MsgBox (lastsal)
ActiveCell.Formula = "=AVERAGE(H21:& lastsal)"
AND
Range("H" & endsal + 2).Select
Dim lastsal As String
lastsal = Selection.Address
MsgBox (lastsal)
ActiveCell.Formula = "=AVERAGE(H21:"& lastsal ")"
Can you help me in getting this to work?