Excel vba 操作
来源:互联网 发布:java 发送get请求 编辑:程序博客网 时间:2024/05/16 17:16
excel2003
vba操作应用快捷键
Alt+F11
Alt+F8
1hello_world
code:
Sub Hello_World() MsgBox ("hello vba")End Sub
2光标定位
code:
Sub Select_Cells() 'ThisWorkbook.Sheets("Sheet1").Range("A1").Select '定位单个光标 'ThisWorkbook.Sheets("Sheet1").Range("A1", "D3").Select '定位光标范围 'ThisWorkbook.Sheets("Sheet1").Range("C:C").Select '定位光标列 ThisWorkbook.Sheets("Sheet1").Range("3:10").Select '定位光标列End Sub
3固定位置的取值和赋值
code:
Sub Select_Cells() 'ThisWorkbook.Sheets("Sheet1").Cells(1, 1).Value = 22 '添加字 'ThisWorkbook.Sheets("Sheet1").Cells(1, 1).Value = "" '清空 ThisWorkbook.Sheets("Sheet1").Cells(1, 1).Value = ThisWorkbook.Sheets("Sheet1").Cells(2, 1).Value End Sub
4固定位置的取值计算
Sub Add_Cells() With ThisWorkbook.Sheets("Sheet1") Dim Cell1, Cell2, Cell3 As Integer Cell1 = .Cells(8, 1).Value Cell2 = .Cells(8, 2).Value Cell3 = Cell1 + Cell2 .Cells(8, 3).Value = Cell3 End With End Sub5固定位置的设置字符串
code:
Sub Add_Cells() With ThisWorkbook.Sheets("Sheet1") Dim Text, Text2 As String Text = "Hello ZXL" Text2 = "my name is matt" .Cells(1, 1).Value = Text End With End Sub
6判断语句(if)+inputbox输入框
code:
Sub Password_Protected() Dim Password, UserPassword As String Password = "Password" UserPassword = InputBox("please enther yout password") If Password = UserPassword Then MsgBox ("access granted") Else MsgBox ("password incorrect") End If End Sub
7 界面交互
1.在excel中加入-自选图形-圆形矩形-右键 设置自选图形格式 设置对齐 颜色...
2.点右键制定宏
code:
Sub Password_Protected() Dim Password, UserPassword As String Password = "Password" UserPassword = InputBox("please enther yout password") If Password = UserPassword Then MsgBox ("access granted") Else MsgBox ("password incorrect") End If End Sub单击后
8 界面交互应用(年龄判断)
code:
Sub SubmitAge()Dim Age As IntegerAge = ThisWorkbook.Sheets("Sheet1").Cells(5, 2).ValueIf Age > 18 ThenMsgBox ("old")ElseMsgBox ("young")End IfEnd Sub9 for语句循环添加
code:
Sub Fill_SEries()For counter = 2 To 6ThisWorkbook.Sheets("Sheet1").Cells(1, counter).ValueNextEnd Sub
0 0
- Excel-VBA文件操作
- excel VBA 简单操作
- EXCEL 操作汇总&&VBA
- VBA 操作excel菜单
- VBA 操作excel菜单
- Excel vba 操作
- [VB/VBA]SQL操作EXCEL
- Excel常用VBA操作命令
- Excel-VBA文件操作1
- Excel-VBA文件操作2
- Excel-VBA文件操作3
- Excel-VBA文件操作4
- Excel-VBA文件操作5
- VBA操作Excel代码收集
- VBA Excel宏常用操作
- VBA Excel宏操作示例
- VBA对EXCEL的操作
- VBA操作Excel小技巧
- 关于产品设计自己的一些想法
- 网页如何有效调用exe
- Number Of Ones题解 codeEval
- 使用javascript解决字符串超长显示的问题
- 5 Reasons to Stick with MySQL
- Excel vba 操作
- About Spring
- 补遗篇之内联与内嵌
- dhcp authoritative参数作用
- 外连接查询
- CocosBuilder 3.0 alpha5 之后将不再更新了,大家怎么看
- iOS开发笔记--cell最右边显示箭头,字符,自定义分割线
- shell中条件判断if中的-z到-d的意思
- C#静态构造函数