Jul 19 2022 09:45 PM
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
Jul 20 2022 01:05 AM
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)"
Jul 20 2022 06:01 AM
@Martin_Weiss the 4 desired characters do not appear.
Jul 20 2022 08:33 AM
Jul 20 2022 04:30 PM
@Martin_Weiss macro only shows the "*****" but not the last 4 characters. No error or break mode.
Jul 21 2022 06:01 AM - edited Jul 21 2022 06:08 AM
SolutionHi @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.
Jul 21 2022 06:01 AM - edited Jul 21 2022 06:08 AM
SolutionHi @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.