vba案列

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函數(shù)4代表“是”和“否”;32代表警告窗口

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

'msgbox函數(shù)vbYesNo代表“是”和“否”;VBQuestion代表警告窗口

If answer = vbYes Then

Cells.ClearContents '如果點(diǎn)擊answer對(duì)話框是yes的,那么將清空所有單元格內(nèi)容

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_ ;_ ¥* ""-""??_ ;_ @_ " '單元格里面的數(shù)字變成價(jià)錢金額

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" '單元格的絕對(duì)引用

End Sub

Private Sub CommandButton1_Click()

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

'相對(duì)單元格的引用結(jié)果跟第一個(gè)一樣

End Sub

打開一個(gè)工作表并給工作表加密!

Sub 按鈕1_Click()

If Application.InputBox("請(qǐng)輸入密碼:") = 123 Then

Range("A1").Value = 10

Else

MsgBox "密碼錯(cuò)誤,即將退去!"

Sheets("sheet2").Select

End If

End Sub


2.在單元格里面輸值以及清除單元格格式以及內(nèi)容

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.單元格序號(hào)填充

Sub cell()

Sub cell()

Dim Icell As Integer

For Icell = 1 To 100

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

'單元格序號(hào)填充

'? 英文注釋? ? ? ? ? The cell number is filled

Next

End Sub

5.for.......next帶循環(huán)語句

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

? ? ? ? ? ? ? ? ? ? ? ? ? ?'單元格序號(hào)填充

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?'? 英文注釋? ? ? ? ? The cell number is filled

Next

End Sub







最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • 本例為設(shè)置密碼窗口 (1) If Application.InputBox(“請(qǐng)輸入密碼:”) = 1234 Th...
    浮浮塵塵閱讀 13,769評(píng)論 1 20
  • 1.1 VBA是什么 直到90年代早期,使應(yīng)用程序自動(dòng)化還是充滿挑戰(zhàn)性的領(lǐng)域.對(duì)每個(gè)需要自動(dòng)化的應(yīng)用程序,人們不得...
    浮浮塵塵閱讀 21,865評(píng)論 6 49
  • 第一章 VBA是什么 Visual Basic Application 一個(gè)Excel文件就是一個(gè)工作簿(Work...
    PyJack閱讀 1,855評(píng)論 0 2
  • 看看下面的Excel界面截圖,“排序”和“篩選”往往在一起,這大概是很多數(shù)據(jù)需要先排序后篩選吧! 在Excel 2...
    完美Excel閱讀 29,010評(píng)論 1 5
  • 每一件絕世無雙的好作品都是以無比寂寞的勤奮為前提,要么是血,要么是汗,要么是大把曼妙的青春時(shí)光。 增長黑客,是一群...
    梅晨斐閱讀 1,584評(píng)論 0 9