VBA (Visual Basic for Applications) is widely used for automating MS-Office products. Most of the time, when you are working with loads of data and want to automate your tasks, VBA comes in very handy.

VBA(用于应用程序的Visual Basic)被广泛用于自动化MS-Office产品。 大多数情况下,当您处理大量数据并希望自动化您的任务时,VBA会非常方便。

Last week, I had to work on dozens of workbooks and had to do some process of data cleaning over them. If I would have done it manually by going on each workbook and cleaning it - the same process for dozens of times, it would have sucked all my energy and would have taken hours to get all done and dusted.

上周,我不得不处理数十本工作簿,并且必须对它们进行一些数据清理过程。 如果我要通过每本工作簿并清洁它来手动完成该过程(同一过程数十次),那将消耗我的所有精力,并且将花费数小时来完成所有工作并除尘。

To avoid this tedious process of cleaning, I decided to go for a shortcut. And, that was writing a VBA script! And, that made the whole process super fast. I was done with my task in a few minutes. Not only it will save you time, but also bring a serious cut on efforts. And, all it takes will be some good knowledge of VBA script and you will rock at work.

为了避免繁琐的清洁过程,我决定寻求捷径。 而且,那是在编写VBA脚本! 而且,这使整个过程变得非常快。 几分钟后,我的任务就完成了。 它不仅可以节省您的时间,而且可以大大减少工作量。 并且,所需要的只是VBA脚本的一些知识,您会在工作中动摇。

一切始于宏 (It all starts with Macros)

As per Microsoft’s definition,

按照Microsoft的定义,

a macro is an action or a set of actions that you can run as many times as you want

宏是一个动作或一组动作,您可以根据需要运行多次

Let’s say, you get a weekly report and it needs some fixes on formatting issues. Every time making those formatting issues correct manually will consume time and you will get bored of doing the same task again and again. Hence, creating a macro for the task will come in very handy.

假设您有一份每周报告,并且需要对格式问题进行一些修复。 每次手动解决这些格式问题都会浪费时间,并且您会一次又一次地厌倦执行相同的任务。 因此,为任务创建宏将非常方便。

Every time you get the weekly report, run the macro, and you are done!

每次获取每周报告时,运行宏,您就完成了!

Macros are just small programs that you can run and those macros will perform certain actions. Let’s say, your task is to go to column A of your Excel dataset and lookup the cell values from other sheets. The lookup results are stored in Column B.

宏只是可以运行的小程序,这些宏将执行某些操作。 假设您的任务是转到Excel数据集的A列并从其他工作表中查找单元格值。 查找结果存储在B列中。

So, you can write a VBA code (that will be your macro) and run it. Hence, the Vlookup will be performed automatically. Not a thing to do!

因此,您可以编写一个VBA代码(将是您的宏)并运行它。 因此,Vlookup将自动执行。 没事做!

This is just a simple example that I am talking about. There can be complicated tasks that may require formatting, cleaning, and even filtering. So, going with the manual approach is too hefty. Hence, VBA comes to the pitch.

这只是我正在谈论的一个简单示例。 可能存在复杂的任务,可能需要格式化,清理甚至过滤。 因此,采用手动方法过于繁琐。 因此,VBA进入了市场。

Okay, I have talked about VBA a lot now. Let’s play with the coding exercise now. I am going with the Vlookup exercise only for now.

好的,我现在已经谈论了很多VBA。 现在开始进行编码练习。 我现在仅进行Vlookup练习。

录制宏是简单的方法! (Record Macro is the easy way!)

Excel provides a feature that will help you in creating your macro. No need to write the code. It will be handled by Excel itself.

Excel提供了一项功能,可以帮助您创建宏。 无需编写代码。 它将由Excel本身处理。

It is an amazing feature. So, if you have to look up a column’s values from another column and you do it regularly, a macro will be very useful for you.

这是一个了不起的功能。 因此,如果您必须从另一列中查找一列的值并定期执行,那么宏将对您非常有用。

But, how to record a macro?

但是,如何记录宏?

Very Simple! Go to Developer > Record Macro. And, all your key actions will be recorded and converted into VBA code. Super Amazing, right?

很简单! 转到开发人员>记录宏。 并且,您所有的关键操作都将被记录并转换为VBA代码。 超级神奇吧?

(Left) Sheet1: Introduce lookup column here (Right) Sheet2: Looking up from this place
(左)Sheet1:在此处介绍查找列(右)Sheet2:从此位置查找

These are the two sheets (sample data) — at one I will be bringing lookup results and will perform the lookup from the right sheet.

这是两张纸(样本数据),我将带来一张查找结果,并从右一张纸开始执行查找。

So, after you start recording, you have to do the same you would do manually. Go to column B, set the column name at B1 and then, apply vlookup formula to the B2 cell, autofill the column, converting the column to values, and replace #N/A by blanks.

因此,在开始录制后,您必须执行与手动相同的操作。 转到列B,将列名设置为B1,然后将vlookup公式应用于B2单元格,自动填充列,将列转换为值,并用空格替换#N / A。

Go to stop recording and now, you can see the macro code. In my case, it looked like.

转到停止记录,现在您可以看到宏代码。 就我而言,它看起来像。

It is the code that Excel generated after I started recording. Hence, you can use this macro or its code to the same task on any excel sheet.

这是我开始记录后Excel生成的代码。 因此,您可以使用此宏或其代码对任何excel工作表执行相同的任务。

The other way i.e the hard way is to write code by yourself from the scratch. But, the Record Macro feature might not be as dynamic as you want it to be. But, at least it gives you a blueprint and you are good to go with changes and the baseline.

另一种方法,即困难的方法是从头开始自己编写代码。 但是,“录制宏”功能可能不会像您期望的那样动态。 但是,至少它为您提供了一个蓝图,并且很好地应对更改和基准。

So, next time you are looking to make things fast. Or, if you are bored with doing the same stuff on excel files again and again, just remember Microsoft has provided some beautiful features to us for crazy automation. That is Macros.

因此,下一次您希望快速进行操作。 或者,如果您无聊一次又一次地在excel文件上做同样的事情,请记住Microsoft为我们疯狂的自动化提供了一些漂亮的功能。 那就是宏。

Peace!

和平!

翻译自: https://medium.com/swlh/rock-the-excel-sheets-with-vba-c5e84e01261d


http://www.taodudu.cc/news/show-6722980.html

相关文章:

  • laravel-excel文档翻译笔记详细
  • 【知识兔】Excel还可以翻译,强大到爆
  • word学习/word如何显示空格/LaTeX格式转为Word格式/ latex中的公式格式如何转换成word中的公式格式/excel复制到word表格过大超出
  • excel单元格删除空格_在Excel数据输入单元格中防止空格
  • Java之基于注解的Excel导出
  • 由损失函数设计原理,重理解交叉熵推导
  • 电子技术——功率耗散
  • 【数据结构】二叉树——理论篇
  • 分布式理论之体系结构
  • 简要介绍 | 交叉熵损失:原理和研究现状
  • 耗散结构
  • 【耗散结构论】耗散结构简介
  • 投影不到电视上
  • Excel中数据转换成甘特图(wps)
  • Excel 甘特图
  • 软考报名表怎么填?
  • 个人简历一般填什么好?怎么制作工作简历?
  • 怎么用matlab做loop_用小程序做微信卖菜社区团购,可行吗?怎么做?
  • 前置仓模式开启生鲜电商下半场,四面楚歌的叮咚买菜们能否突围?
  • 疫情大考下的食品饮料赛道:长期战略短期战术两手抓
  • 有头有脸的互联网公司都在“卖菜”
  • 最后一公里配送仍待破题 社区电商服务还得精准点儿
  • 资本加持、弯道超车的社区拼团是如何开创电商新时代的?
  • 社区团购的“生意经”,有钱就能“念”好吗?
  • 工作组win7计算机无法访问,win7系统无法访问工作组怎么办
  • xp查找win10工作组计算机,主编教您win10系统加入xp工作组的方法
  • Win10出现身份验证错误,要求的函数不受支持 可能是由于CredSSP加密Oracle修正。
  • win7系统搭建svn服务器,Win7系统如何使用VisualSVN Server搭建SVN服务器?
  • win10无法打开匿名级安全令牌_Win10安装Sql Server 2016错误解决教程
  • 验证远程计算机的连接遇到,win7系统进行远程桌面连接出现身份验证错误的图文步骤...

用VBA摇滚Excel工作表相关推荐

  1. 用VBA去除Excel工作表保护密码

    今天帮同事解决个EXCEL问题,现记在这,以作备忘 现象: 想要修改保护单元 格的内容,在使用"工具"菜单"保护"子菜单的"撤消工作表保护" ...

  2. 使用VBA将Excel工作表分割成多个文件

    问题描述 有一个表格,具体数据如下图所示.这里需要按城市(即B列数据)对表格进行拆分,拆分出多个以城市名称命名的xlsx文件,每个xlsx文件都只包含当前城市的数据.  相关资料 之前没有接触过Exc ...

  3. VBA添加Excel工作表

    看到这个题目,很多人可能会说:添加工作表需要解释吗?连VBA小白都会用呀!没错,大家可能经常用到,但是大家是否都知道下面的用法呢,可能还真不一定呦! VBA添加工作表的代码看起来确实很简单. Work ...

  4. vba ado返回集合_利用ADO,实现同一文件夹下多个EXCEL工作表的数据汇总

    大家好,今天继续讲解<VBA数据库解决方案>,今日讲解的是第37讲,利用ADO,实现同一文件夹下多个EXCEL工作表的数据汇总.最近的内容实用性比较强,如今日的内容,只把需要汇总的EXCE ...

  5. VBA中使用EXCEL工作表函数

    EXCEL的VBA有两个函数库,一个是VBA的函数库,另一个是EXCEL工作表函数,也就是我们在单元格中使用的函数,两个函数库不是完全一样的.例如FIND(),VLOOKUP(),在VBA的函数库中是 ...

  6. vba 将数组作为参数传递_将VBA数组写入工作表时转置(Transpose)的利用

    大家好,最近推出的内容是"VBA信息获取与处理"中的部分内容,这套教程面向中高级人员,涉及范围更广,实用性更强,现在的内容是第四个专题"EXCEL工作表数据的读取.回填和 ...

  7. navicat 只对比一张表的数据_Excel VBA批量新建工作表(对比数据透视表的使用)...

    在之前的一篇文章中,分享过用数据透视表的方法批量新建工作表. https://zhuanlan.zhihu.com/p/115191339​zhuanlan.zhihu.com 本次将用VBA的方式快 ...

  8. SAP 导出 HTML,【我sap这导出数据表格export.mhtml怎么转换为 excel 工作表.xlsx】excel生成html表格数据...

    如何把Html网页格式转成Excel表格 1.单击数据--导部数据--新建Web查询. 2.勾选我可以此内容,允许播放,单击继续按钮. 3.在地址栏输入网站地址,转到此网站里面. 4.跳转到指定网页, ...

  9. C#将一个excel工作表根据指定范围拆分为多个excel文件

    C#将一个excel工作表根据指定范围拆分为多个excel文件 微软Excel没有提供直接的方法来拆分excel文件,因此要拆分一个excel文件最简单的方法可能就是手动剪切和粘贴了,除此之外,还有其 ...

最新文章

  1. POI按照源单元格设置目标单元格格式
  2. 2016年第七届蓝桥杯 - 国赛 - C/C++大学B组 - D. 机器人塔
  3. 利用SharedPreferences完成记住账号密码的功能
  4. 搭建Windows Embedded Compact 7开发环境
  5. 县级外业调查及举证软件_我公司中标江西省第三次全国国土调查县级建库软件项目...
  6. PlaceholderTextView
  7. 推荐一个Oracle数据库学习网站
  8. DSP CCS5.5安装步骤
  9. 10种提高WordPress访问速度的方法
  10. js分页插件:首页,上页,快退,页码,快进,下页末页,跳转,使用模板,灵活自由
  11. 湖北工业大学计算机学院考研资料,湖北工业大学计算机学院836数据结构历年考研真题汇编.pdf...
  12. 苹果微信更新不了最新版本_微信登录提示版本过低 微信登录不了的解决办法...
  13. 立创eda学习笔记二:画pcb板流程(极简入门版)
  14. 红孩儿编辑器的模块设计8
  15. 单元测试chapter2
  16. LNMP架构部署详细步骤
  17. 关于屏幕分辨率适配的教程
  18. mybatis动态SQL多条件查询1 - if 标签
  19. Mahalanobis距离(马氏距离)
  20. 一篇“从入门到上手”的PCB设计教程

热门文章

  1. 产品迭代开发 迭代发布_迭代开发用例
  2. 深入学习Java虚拟机笔记
  3. ERP咨询顾问的职责
  4. 小觅相机运行VINS-Fusion(一)
  5. 我喜欢的儿歌:小白小白上楼梯
  6. 小米开放平台应用自动发布接口集成后总是返回密码错误
  7. Android回弹效果新思考与更加易用的实现
  8. java park unpark
  9. 面试官:1 到 1000 之间有多少个 7?
  10. 终生好习惯:早上白开水一杯——年轻漂亮一辈子