Forum Discussion
Inserting formula in a cell
Hello, I'm trying to insert a RIGHT formula in one column but my macros goes into break mode.
Wanted the variable cell to be whatever cell I selected with the mouse before running the macro. Any Advice?
Sub AddFormula()
Dim cell As Range
Set cell = Selection
Range(cell) = Right("*****", 4)
End Sub
Hi NRASA0743
yes, that's because this was the formula that you wanted to put in the cell based on your original question.
Sorry, now I think I understand: You want only the last 4 characters of whatever is currently in the cell? This should do it:
Selection.Value = Right(Selection.Value, 4)
Please note that this works only for single cells, not for a selection of multiple cells.
6 Replies
- Martin_WeissBronze Contributor
Hi NRASA0743
you do not need a cell variable. And you need to set the RIGHT-formula in quotation marks.
This should do it:
Selection.FormulaR1C1 = "=RIGHT(""****"",4)"
- NRASA0743Copper Contributor
Martin_Weiss the 4 desired characters do not appear.
- Martin_WeissBronze Contributor