PGSystemTester

Excel UDF Show Cell Formula As Text

Jul 6th, 2017
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function FormulaAsText(Cell As Range, Optional R1C1_METHOD As Boolean) As String
  2. 'PGCodeRider
  3. 'Note in Excel 2013 and later, MS implemented an almost identical formula for this =FORMULATEXT(
  4.  
  5. If Cell.Cells.Count > 1 Then
  6.     'not necassary but Formula will #VALUE without this check
  7.    FormulaAsText = "Must Select Single Cell"
  8.    
  9. ElseIf R1C1_METHOD = False Then
  10.     FormulaAsText = Cell.Formula
  11.  
  12. Else
  13.     FormulaAsText = Cell.FormulaR1C1
  14.    
  15. End If
  16.  
  17. 'Note using R1C1 Can be useful if you're looking at cells and want to see a functional difference accross rows in columns.
  18. 'Exammple is if regular cell formula method is used for cells in row 3 referenceing one cell above, they would appear as =A2 =B2 = C2...  etc.
  19. 'However with R1C1 You would consistently get a formula of =R[-1]C for all cells.
  20.    
  21. End Function
Add Comment
Please, Sign In to add comment