vba案列

作者: 心的知觉 | 来源:发表于2017-03-29 13:42 被阅读0次

Sub 九九剩法()

Dim i As Integer

Dim j As Integer

For i = 1 To 9

        For j = 1 To 9

           im = i Mod 2

          k = i & "×" & j & "=" & i * j

            If i <= j Then

            Sheets("Sheet1").Cells(j, i) = k

            Cells(j, i).Interior.ColorIndex = 3

If im = 0 Then

Cells(j, i).Interior.ColorIndex = 6

End If

End If

Next j

Next i

End Sub

案列二

Sub fun()

MsgBox "Entered value is" & Range("A1").Value & vbNewLine & Range("B1").Value

   '输出字符串entered value is单元格A1的值以及换行单元格B1的值

End Sub

案列三

Sub fun()

Dim answer As Integer

answer = MsgBox("Are you sure you want to empty the sheet?", 4 + 32, "Empty  sheet")

'msgbox函数4代表“是”和“否”;32代表警告窗口

answer = MsgBox("Are you sure you want to empty the sheet?", vbYesNo + vbQuestion, "Empty Sheet")

'msgbox函数vbYesNo代表“是”和“否”;VBQuestion代表警告窗口

If answer = vbYes Then

Cells.ClearContents '如果点击answer对话框是yes的,那么将清空所有单元格内容

Else

'do nothing

End If

End Sub

宏的录制方法

Sub 宏41()

'

' 宏41 宏

'

' 快捷键: Ctrl+s

'

Selection.NumberFormatLocal = "0.00%" '单元格里面变成0.00%

End Sub

Sub 宏2()

'

' 宏2 宏

'

'

Selection.NumberFormatLocal = _

"_ ¥* #,##0.00_ ;_ ¥* -#,##0.00_ ;_ ¥* ""-""??_ ;_ @_ " '单元格里面的数字变成价钱金额

End Sub

Sub 宏6()

'

' 宏6 宏

'

'

ActiveCell.FormulaR1C1 = "salse" '在单元格中填写sales

ActiveCell.Offset(1, 0).Range("A1").Select

ActiveCell.FormulaR1C1 = "production" '在单元格中填写production

ActiveCell.Offset(1, 0).Range("A1").Select

ActiveCell.FormulaR1C1 = "logistics" '在单元格中填写logistics

ActiveCell.Offset(1, 0).Range("A1").Select

End Sub

Private Sub CommandButton3_Click()

Range("E4").Formula = "=B12*2"

End Sub

Private Sub CommandButton2_Click()

Range("E4").FormulaR1C1 = "=R12C2*2" '单元格的绝对引用

End Sub

Private Sub CommandButton1_Click()

Range("E4").FormulaR1C1 = "=R[8]C[-3]*2"

'相对单元格的引用结果跟第一个一样

End Sub

打开一个工作表并给工作表加密!

Sub 按钮1_Click()

If Application.InputBox("请输入密码:") = 123 Then

Range("A1").Value = 10

Else

MsgBox "密码错误,即将退去!"

Sheets("sheet2").Select

End If

End Sub

2.在单元格里面输值以及清除单元格格式以及内容

Sub inserte()

Dim Color As Integer

Range("A1:A2").Select

Selection.EntireRow.Insert

ActiveCell.FormulaR1C1 = "text"

ActiveCell.FormulaR1C1 = "formulas"

Range("A1:A2").BorderAround Weight:=1

Range("A1:A6").Clear

End Sub

3.The properties of the cell selection

Sub Rngselect()

'Sheet1.Range("A3:F6, B1:C5").Select

Sheet2.Range("$A$3:F6 ,$C$5:$G$7").Select

'

End Sub

Sub Rngselect1()

'Sheet1.Range("A3:F6, B1:C5").Select

Sheet1.Range("A3:F6 ,C5:G7").Select

'Select the merge cell section

End Sub

Sub Rngselect2()

'Sheet1.Range("A3:F6, B1:C5").Select

Sheet1.Range("A3:F6  C5:G7").Select

'Select the intersecting cell section

End Sub

4.单元格序号填充

Sub cell()

Sub cell()

Dim Icell As Integer

For Icell = 1 To 100

Sheet2.Cells(Icell, 1).Value = Icell

'单元格序号填充

'  英文注释          The cell number is filled

Next

End Sub

5.for.......next带循环语句

Sub cell()

Dim Icell, sum, j As Integer

For Icell = 1 To 100

sum = Icell + 1

j = j + sum

Sheet2.Cells(Icell, 1).Value = j

                           '单元格序号填充

                               '  英文注释          The cell number is filled

Next

End Sub




相关文章

网友评论

      本文标题:vba案列

      本文链接:https://www.haomeiwen.com/subject/rvisbttx.html