The application of VBA in Excel (I.)

Source: Internet
Author: User

Directory

ActiveCell

ActiveWorkbook

AdvancedFilter

AutoFill

ActiveCell

1. Check whether the active cell exists

Sub activeCell()
If ActiveCell Is Nothing Then End If
End Sub

2. Set the active cell by specifying an offset

Sub offset()
ActiveCell.Offset(RowOffset:=-2, ColumnOffset:=4).Activate
End Sub

The first parameter of the offset function is the offset of the row, the second parameter is the offset of column (which can be unspecified), and the value can be given directly when used, such as offset (2, 4). The value is less than 0 offset in the opposite direction. Offset (). Activate with offset (). The select is equivalent in effect.

3. Set the current value of the active cell

Sub SetValue
ActiveCell.Value = "Hello World!"
End Sub

4. Set the formula for the currently active cell

Sub fomula()
ActiveCell.Formula = "=SUM($G$12:$G$22)"
End Sub

To assign a formula's expression directly to the Formula property, the formula expression can refer to the Formula menu in Excel, such as summing, counting, averaging, and so on.

5. Get the address of the currently active cell

Sub selectRange()
MsgBox ActiveCell.Address
End Sub

The format of the address, such as: $A $11.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.