Syntax Highlighters: VBA, Excel Function, Power Query M Code, and SQL


Feb 28, 2002
Highlighting code snippets by using BB code helps separating the code from the actual question in the post content, and also makes the code more readable. Codes posted this way could be also copied easily by using the copy icon at the top right corner of the code area. Therefore we strongly recommend using BB code to highlight code snippets to make it as easy as you can for the volunteers who are trying help you, and likely get faster replies.

To make the highlighting process easier, we implemented the single-click toolbar buttons when we migrated to the new forum software last year, <vba/> and <rich/>. You simply paste the code, select it in the editor, and click the corresponding button on the toolbar to wrap the code in necessary tags.

We are happy to announce that we recently implemented syntax highlighters for Power Query M Code and Excel Functions, and also created dedicated icons for all languages that are mostly being used, and we placed the buttons on the post editor toolbar as shortcuts to make them easily accessible.


You can find the sample outputs below to see how it looks.

Excel Formula:

VBA Code:
Sub howManyRows()
Dim rng As Range
    'Get the name range
    Set rng = Sheet1.Range("Expenses")
    MsgBox rng.Rows.Count, vbOKOnly + vbInformation, "Total Rows"
End Sub

Power Query:
    // Get the table data
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content]

SELECT ExerciseLog.LogDate, Sum(ExerciseLog.Calories) AS SumOfCalories
FROM ExerciseLog
GROUP BY ExerciseLog.LogDate;

Rich (BB code):
Sub howManyRows()
Dim rng As Range
    Set rng = Sheet1.Range("Expenses")
    MsgBox rng.Rows.Count, vbOKOnly + vbInformation, "Total Rows"
End Sub

You can still post code in other languages such as HTML, JavaScript by using the </> button on the toolbar.

Please help the community members who are trying to answer your question, and try to use code tags to highlight your code snippets.

While you are checking the toolbar for these new buttons, please also look for the XL2BB button as the last one on the toolbar and also consider downloading free XL2BB add-in to post your sample Excel range which is also a great help to other members answering questions. Without exchanging workbook files, sample range posted by using XL2BB can be transferred to Excel easily that would save other members to create the same data structure in Excel manually.

Thank you!

Some videos you may like

Watch MrExcel Video

Forum statistics

Latest member

This Week's Hot Topics