Excel VBA practice answer
19. General practice question 1 Answer

Excel VBA practice
last updated:08-16-2019

19. General practice question 1 Answer

Some of this topic was processed by machine translation. Original

This is the answer page for the macro VBA exercise.

Macro VBA exercises

As explained in the introduction to Macro VBA,
Excel VBA is a programming language used in the macro function that automates Excel operations. VBA is short for _Microsoft Visual Basic Applications_ In this VBA introductory series As an introduction to macro VBA which is required in practice

For ~ Next
Get last row
Four arithmetic operations

Use the above to complete the following exercises.

VBA macro excel

In the table above, calculate the unit price in column A x the quantity in column B, and give the amount in column C.

Calculate the unit price x quantity from the second row to the last row of the table with For Next.

Thinking time

Thinking time starts

The sinking time ends

Macro VBA practice answer

So, here is the macro VBA code for the answer.

Sub practice1()
  Dim i As Long
  For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row
    Cells(i, 3) = Cells(i, 1) * Cells(i, 2)
  Next i
End Sub

*Value is omitted.

In the above case,
Cells (Rows.Count, 1) .End (xlUp) .Row
this is,
Cells (1, 1) .End (xlDown) .Row

This is the same, but normally you should use End (xlUp).
No explanation is required for the macro VBA code of the answer.

If you can't write this,
Please check the previous contents again.

Please memorize the above answer as a fixed phrase.
Practice so that you can write as it is.

This time it was to say "For ~ Next",
If you write using Do ~ Loop,

Sub practice2()
  Dim i As Long
  i = 2
  Do While Cells(i, 1) <> ""
    Cells(i, 3) = Cells(i, 1) * Cells(i, 2)
    i = i + 1
End Sub

Do While Cells(i, 1) <> ""
this is,
Do Until Cells(i, 1) = ""
This is fine.

To determine if a cell has a value
Judgment is based on "" (continuous double quotation).
"(Double quotations) enclose characters,
It means that the character is not empty.

Articles with the same theme "Excel VBA practice answer"

19. General practice question 1 Answer
26. General practice question 2 Answer
30. General practice question 3 answer
36. General practice question 4 answer
43. General practice question 5 answer
50. General practice question 6 answer
67. General practice question 7 answer

  • >
  • >
  • 19. General practice question 1 Answer

  • 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