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

smozgur

BatCoder
Joined
Feb 28, 2002
Messages
2,656
Highlighting code snippets by using BB code helps separate 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 to 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 the 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 the languages that are mostly being used and placed the buttons on the post editor toolbar as shortcuts to make them easily accessible.

1694534305001.png


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

Excel Formula:
=VLOOKUP(A2,E2:I36,2,FALSE)

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:
let
    // Get the table data
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content]
in
    Source

Python:
df = xl("A1:A6", headers=True)
df["Reversed"] = df.loc[:,"Original"].apply(lambda x: x[::-1])
df[["Reversed"]]

SQL:
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!
 

Forum statistics

Threads
1,223,246
Messages
6,170,996
Members
452,373
Latest member
TimReeks

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top