Vba insert triangle in cells in Excel

For example, I want to show whether Sales has increased or decreased compared to previous period using Triangle / Inverted Triangle - how can I add the same using VBA?

excel vba insert triangle in cells

To do it in Excel, here is the answer:

a) First the character code for Triangle and Inverted Triangle should be obtained. For that, click on "Symbol" under "Insert" as shown below. In the "Symbol" dialog box click on the Symbol of choice and note down the Character code.

In this case it is Hex 25B2 for Triangle and 25BC for Inverted Triangle.

excel vba insert triangle in cells

a) Click on any cell in the Table. In the Ribbon, "Table Tools" Design tab appears. Click on "Total Row" under "Table Style Options". "Total Row" appears at the end of the Table.

b) Use the Hex codes to fill the cell appropriately with Triangle or Inverted Triangle using ChrW(CharCode in Hex) function after applying the condition using VBA (see macro below).

  1. Option Explicit
  2. Sub InsertSymbols()
  3. Dim i As Integer
  4. '''
  5. 'Loop through Table
  6. For i = 5 To 14
  7. If ActiveSheet.Range("AB" & i) > ActiveSheet.Range("AC" & i) Then
  8. 'Sales decreased compared to last period - use Inverted Triangle.
  9. ActiveSheet.Range("AD" & i) = ChrW(&H25BC)
  10. Else
  11. 'Sales increased compared to last period - use Triangle.
  12. ActiveSheet.Range("AD" & i) = ChrW(&H25B2)
  13. End If
  14. Next i
  15. '''
  16. End Sub

Result after Macro execution:

excel vba insert triangle in cells

 

You can find similar Excel Questions and Answer hereunder

1) How do I assign a macro to a shape using VBA?

2) How can I remove hyperlinks from a range of cells?

3) Want to use Microsoft Outlook in Excel. Here some basic explanation to get you started

4) How do I copy a Table from one location to another and retain all formulas, formats and columnwidths?

5) How can I add a legend to a chart using VBA?

6) Applying a countif formula only to visible cells in a filtered list in Excel

7) How do i put double quotes in a string in vba in Excel

8) How to delete rows with Excel VBA

9) How do I enter a formula in a cell using VBA (using Absolute Reference)?

10) How to display messages boxes in VBA with the msgbox function

 

Here the previous and next chapter