# VBA basics15. Four arithmetic operations and annotations (comments)

Excel macro basics and applications, introduction to Excel VBA • >
• >
• 15. Four arithmetic operations and annotations (comments)
last updated：08-15-2019

## 15. Four arithmetic operations and annotations (comments)

Some of this topic was processed by machine translation. Original

Excel is a spreadsheet software, so if you can't calculate it, it won't be a story.

The first is the arithmetic operation (addition / subtraction remainder) operator.
This is the same as the worksheet operator.

### Arithmetic operators

 Operator Description + Addition - Subtraction * Multiplication / Division \ Quotient of division Mod remainder of division ^ Power

If used normally, there will be no problem.

If you need a calculation priority,
Please be sure to enclose with () and specify the calculation order.
Stop writing statements that rely on operator precedence as it is difficult to understand.
Therefore, we will not explain the priority order.

I do n’t think it ’s necessary, but as an example
A1 cell has a unit price of 300
In B1 cell, the quantity is 5
This is a case where 1500 is put in C1 cell as the amount of money.

``` Sub practice1() 　　Cells(1, 3).Value = Cells(1, 1).Value * Cells(1, 2).Value End Sub ```

This explanation is unnecessary.
The problem is that even if you look at this macro, it is not clear what calculation is being performed.
C1 cell = A1 cell * B1 cell
I understand this, but it's unclear what it means.

So, add a comment so that you know what you are doing.

### Comment

``` Sub practice1() 　　'Amount = Unit price * Quantity 　　Cells(1, 3).Value = Cells(1, 1).Value * Cells(1, 2).Value End Sub ```

In this way, a comment (annotation) follows' (single quotation).

Comments are not relevant to macro execution.
It has no effect on execution.

Comments can also be written from the middle of the line.

``` Sub practice1() 　　Cells(1, 3).Value = Cells(1, 1).Value * Cells(1, 2).Value 'Amount = Unit price * Quantity End Sub ```

'(Single quotation) is the only comment after,
Until then, you can write macros normally.

In this case, either of the above writing methods may be used.
I write comments for only one line behind
Comments on several lines are basically written from the beginning,
These are each person, and adapt to your organization's coding rules, if any.

In addition, in the case of a comment on a larger round (procedure, etc.)

``` '*************************************************************** '* Practice four arithmetic operations '*************************************************************** Sub practice1() 　　Cells(1, 3).Value = Cells(1, 1).Value * Cells(1, 2).Value 'Amount = Unit price * Quantity End Sub ```

Like this, I write comments so that they stand out.
Since it is a comment, there is no particular rule on how to write it.
To make it easier to see when you see it later,
Write it so that it is easy to understand when you show it to others.

### Articles with the same theme "VBA basics"

• >
• >
• 15. Four arithmetic operations and annotations (comments)

• If you find this site useful, please share and bookmark.

I'm going to pay close attention to the description,
If you have any mistakes or suggestions,「Contact Us」I hope you will let me know.
Use the posted VBA code at your own risk.
We are not liable for any damages such as data corruption.

If you find this site useful, please share and bookmark.
To the bottom of the text