vba insert triangle in cells in Excel

Q153. In Excel, how do I add a symbol like Triangle / Inverted Triangle for indicating trends in a cell using VBA?

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 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 excel excel vba insert triangle in cells

 

You can find similar Excel Questions and Answer hereunder

1) How can I set non-contiguous print area using VBA?

2) How can I add a Timestamp after macro execution?

3) How do I enter a formula in a cell using VBA (using Relative Reference)?

4) Write to text file without quotes in vba in Excel

5) How to add a link in a sheet to another sheet

6) How can I hide all comments in my WorkSheet using VBA?

7) How can worksheet functions be accessed in VBA?

8) I have a macro that takes a lot of time for execution - how can I keep the user informed that the macro is running?

9) Vba clear the contents of an entire sheet in Excel

10) How can I identify cells with Circular Reference in a WorkSheet?

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

12) How can I enter a picture in a cell?

13) How can I list all files in a folder using VBA?

14) How can I clear cell after activating a routine when there is a change in value of a cell?

15) How can I find the last used cell in a Column in VBA?