Remove Arrows in Excel Formulas

Remove Arrows in Excel Formulas

Remove Arrows:

Removes all arrows following Precedents, Dependents or both. In Excel we have three options available which can remove individual arrow or all as mentioned below:

  • Navigate Formulas tab
  • Locate Formula Auditing group as shown below
  • Select appropriate remove arrow method from dropdown as shown below

Let’s put code to achieve automation in Excel. Point to be noticed will be following VSTO (Visual Studio Tools for Office) as example hence following prerequisites are recommended for C# or VB.Net code examples:

Prerequisites:

  • Visual Studio 2015 or above having Microsoft Office for Developer Tool installed
  • Create Excel Addin in C# code style (Visual Studio Tools for Office)
  • Excel 2010 or above
  • Create a ribbon designer and put button

C# code example: Remove precedents arrow

private void btnRemovePrecendentsArrows_Click(object sender, RibbonControlEventArgs e)
{
	//Get current selection
	excel.Range oRange = Globals.ThisAddIn.Application.Selection;

	//check if selection has formula
	if (Globals.ThisAddIn.Application.WorksheetFunction.IsFormula(oRange))
	{
		oRange.ShowPrecedents(Remove: true);	
	}
}

C# code example: Remove dependents arrow

private void btnRemoveDependentsArrows_Click(object sender, RibbonControlEventArgs e)
{
	//Get current selection
	excel.Range oRange = Globals.ThisAddIn.Application.Selection;

	//check if selection has formula
	if (Globals.ThisAddIn.Application.WorksheetFunction.IsFormula(oRange))
	{
		oRange.ShowDependents(Remove: true);	
	}
}

C# code example: Remove all arrows

private void btnRemoveArrows_Click(object sender, RibbonControlEventArgs e)
{
	//Get worksheet reference
	excel.Worksheet oWorksheet = Globals.ThisAddIn.Application.ActiveSheet;

	oWorksheet.ClearArrows();
}

VB.Net code example: Remove precedents arrow

Private RemovePrecedents_Click(sender As Object, e As RibbonControlEventArgs) Handles RemovePrecedents.Click

    'Bind Range object from selection
    Dim oRange As excel.Range
    oRange=Globals.ThisAddIn.Application.Selection

    'check if selection has formula
    if Globals.ThisAddIn.Application.WorksheetFunction.IsFormula(oRange) Then
        oRange.ShowPrecedents(Remove := True)
    End If

End Sub

VB.Net code example: Remove dependents arrow

Private RemoveDependents_Click(sender As Object, e As RibbonControlEventArgs) Handles RemoveDependents.Click

    'Bind Range object from selection
    Dim oRange As excel.Range
    oRange=Globals.ThisAddIn.Application.Selection

    'check if selection has formula
    if Globals.ThisAddIn.Application.WorksheetFunction.IsFormula(oRange) Then
        oRange.ShowDependents(Remove := True)
    End If

End Sub

VB.Net code example: Remove all arrows

Private Sub btnRemoveArrows_Click(sender As Object, e As RibbonControlEventArgs) Handles btnRemoveArrows.Click
	'Bind worksheet object reference
	Dim oWorkSheet as excel.Worksheet
	oWorkSheet = Globals.ThisAddIn.Application.ActiveSheet

	'Remove all arrows
	oWorkSheet.ClearArrows()
End Sub

VBA code example: Remove precedents arrow

Public Sub RemovePrecedents()
    Selection.ShowPrecedents Remove:=True
End Sub

VBA code example: Remove dependents arrow

Public Sub RemoveDependents()
    Selection.ShowDependents Remove:=True
End Sub

VBA code example: Remove all arrows

Public Sub RemoveAllArrows()
    ActiveSheet.ClearArrows
End Sub

Output: Before

Output: After code execution

Leave a Reply

Your email address will not be published.