当前位置:网站首页>VBA simple macro programming of Excel
VBA simple macro programming of Excel
2022-07-01 18:55:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
Excel And VBA Simple macro programming
excel It is a classic data analysis tool , It contains many built-in functions , But the actual situation is sometimes much more complicated , and excel Macro programming of provides the function of user-defined functions , There is just a teacher who needs help to do some data analysis , I just learned , Here are my study notes . I use excel2013. If there is any discrepancy, please refer to .
List of articles
1、 preparation
- Open the development tools panel (excel By default, the main tab of does not have a development tool tab )
file -> Options -> Custom ribbon ->
At this time, the main tab has a development tool item
- Get into vba edit
Click on visual basic Get into
stay VBAProject Right click -> Insert -> modular An edit file appears, as shown in the following figure
Then you can write vba Code .
2、VBA Programming
2.1 Module declaration
Similar to a program , A module should have a main program entry, that is, module declaration , Such as Sub sname() ··· ··· End Sub
2.2 Variable declaration and assignment
The declaration format is : Dim ‘ Variable name ’ As ‘ Variable type ’ Such as Dim i As Integer Dim str As String The assignment format is : i = 3 str = “hello world!” Direct equal sign assignment
data type | Defining symbols | remarks |
|---|---|---|
character string | String | |
integer | Integer | -32768~32767 |
Long integer numbers | Long | -2147483648~2147483647 |
Single precision floating point numbers | Single | Accuracy of 6 |
Double precision floating point numbers | Double | Accuracy of 14 |
Date type | Date | |
Boolean type | Boolean | |
Variant | Variant | Universal type , Avoid using |
Object type | Object | Not in depth |
enum |
Enumeration type data definition format : Public|Private Enum Variable name member 1[= Constant expression 1] member 1[= Constant expression 1] ··· ··· End Enum for example : Public Enum WorkDays Sunday Monday Tuesday Wednesday Thursday Friday Saturday End Enum
2.3if-else structure
If ······ Then
  ······
ElseIf ······ Then
  ······
Else
  ······
End If2.4 Loop structure
Do While ······
  ······
Loop
For i = 0 To 100 Step 1
  ······
Next iJump out of for The loop can be used Exit For
2.5 Comparison operator
name | Operator |
|---|---|
be equal to | = |
It's not equal to | <> |
Less than | < |
Less than or equal to | <= |
Greater than | > |
Greater than or equal to | >= |
string matching | Like |
2.6 notes
VBA Single line comments in are in single quotation marks ' identification
3、 Common functions
3.1 Get table data
- For the first i That's ok j Column cell data
Sheets(‘ Table name ’).Cells(i,j).Value - For the first i Row data
Sheets(' Table name ').Rows(i) - For the first j Column
Sheets(' Table name ').Columns(j) - Get a piece
Range("a1:b60")
3.2 Copy cells and keep the original cell column width
Sheets(name_1).Cells(i, k).copy
Sheets(name_result).Cells(i,k).PasteSpecial xlPasteColumnWidths3.3 Set cell 、 Color of a row or column
Sheets(name_1).Rows(i).Interior.ColorIndex = 3'
Sheets(name_1).Rows(i).Font.ColorIndex = 1
Sheets(name_1).Cells(i,j).Interior.ColorIndex = 3'
Sheets(name_1).Cells(i,j).Font.ColorIndex = 13.4 Get the number of useful columns and rows of the table
irows1 = Sheets(name_1).UsedRange.Rows.Count
icolumns1 = Sheets(name_1).UsedRange.Columns.Count4、 Debugging operation
Shortcut key | function |
|---|---|
F8 | Run sentence by statement |
Shift+F8 | Run process by process |
Ctrl+F8 | Run to the cursor |
F9 | Add a breakpoint at the cursor |
debugging -> Add monitoring | Add monitoring |
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/130843.html Link to the original text :https://javaforall.cn
边栏推荐
- R语言使用epiDisplay包的followup.plot函数可视化多个ID(病例)监测指标的纵向随访图、使用n.of.lines参数指定显示的病例数
- 用GSConv+Slim Neck改进Yolov5,将性能提升到极致!
- Must see, time series analysis
- app发版后的缓存问题
- 540. Single element in ordered array / 1684 Count the number of consistent strings
- 如何在自有APP内实现小程序实现连麦直播
- The R language uses the tablestack function of epidisplay package to make statistical summary tables (descriptive statistics based on the grouping of target variables, hypothesis testing, etc.). If th
- Lumiprobe bifunctional crosslinker sulfo cyanine 5 bis NHS ester
- 每周推薦短視頻:警惕“現象”與“問題”相互混淆
- R language ggplot2 visualization: visualize the line graph and add customized Y-axis label information to the line graph using the labels function
猜你喜欢

Mise en place d'une plate - forme générale de surveillance et d'alarme, quelles sont les conceptions nécessaires dans l'architecture?

搭建一个通用监控告警平台,架构上需要有哪些设计

Lumiprobe非荧光炔烃丨EU(5-乙炔基尿苷)

AI 训练速度突破摩尔定律;宋舒然团队获得RSS 2022最佳论文奖

ACM MM 2022视频理解挑战赛视频分类赛道冠军AutoX团队技术分享

Solution: you can ping others, but others can't ping me

如何在自有APP内实现小程序实现连麦直播

Technology implementation and Architecture Practice

Leetcode-83 delete duplicate elements in the sorting linked list

精耕渠道共谋发展 福昕携手伟仕佳杰开展新产品培训大会
随机推荐
Using OpenSSL encryption to rebound shell traffic
ES6 summary "suggestions collection" of array methods find(), findindex()
How to operate technology related we media well?
PriorityQueue的用法和底层实现原理
Leetcode-141环形链表
【快应用】Win7系统使用华为IDE无法运行和调试项目
Mise en place d'une plate - forme générale de surveillance et d'alarme, quelles sont les conceptions nécessaires dans l'architecture?
Five degrees easy chain enterprise app is newly upgraded
R language uses follow up of epidisplay package Plot function visualizes the longitudinal follow-up map of multiple ID (case) monitoring indicators, and uses n.of The lines parameter specifies the num
R language uses the DOTPLOT function of epidisplay package to visualize the frequency of data points in different intervals in the form of point graph, and uses PCH parameters to customize the shape o
研究了11种实时聊天软件,我发现都具备这些功能…
解决方案:可以ping别人,但是别人不能ping我
2020, the regular expression for mobile phone verification of the latest mobile phone number is continuously updated
About enterprise middle office planning and it architecture microservice transformation
6款红黄黑榜摄像头评测:谁最安全?谁画质好?从此让你不再踩雷
隐私沙盒终于要来了
[Chongqing Guangdong education] basic psychology reference materials of Tianjin Normal University
磁盘的基本知识和基本命令
2020,最新手机号码手机验证正则表达式,持续更新
斯坦福、Salesforce|MaskViT:蒙面视觉预训练用于视频预测