Dingrui‘s Blog

Data Science · Accounting & Finance · Random Thoughts

Category: VBA

Excel 数组公式 , Alteryx, VBA 与R

这个星期来PwC上班以后,第一次又重新干起了老本行,写VBA和做template (Excel Based)。

做template,最痛苦的事,莫过于design你的template。一方面要囊括尽可能多的,有用的信息给用户,另一方面又要考虑用户会怎么会去使用你的template (这一点我在悉尼大学工作的时候和Casey同学学习到了很多)。PwC又尤其注重你的效率,所以还得考虑到后续的功能增删所耗费的时间与精力。总之让我深刻体验到了,在非码农部门coding的痛苦。

  1. 没有产品设计手册
    咱们就来简化一点,也别来个手册文档了,能把要求说清楚就不错了,更别提能老老实实写在纸面上而且保证后面不赖账。说多了都是泪
  2. 不合理的预期
    Coding 并不是万能药,尤其是在这么一个快节奏的工作环境,经常就是4,5个小时内就要开发完成,想想看这也不太可能。更别提VBA那个屎一样的coding 感受,真是欲仙欲死。

吐槽完毕,开始聊聊我觉得有意识的地方。

数组公式

好久没写数组公式了,这几天才反应过来,数组公式和R其实写起来感觉差不多,尤其如果你比较习惯R里面向量化的写法的话。

Read More

A Simple Way to Call VBA Macro and Pass Arguments From R and Python

Sometimes you may encounter huge legacy VBA codes and you are so redundant to re-develop them in other languages (ie. R and Python). However, you really want to add running VBA codes in your workflow. Now there is a simple solution for R and Python. (Tested on Windows OS)

Sample VBA code

We have following macro.


Public Sub Test_Add(Arg1, Arg2) Sheets(1).Range("a1").Value = Arg1 + Arg2 End Sub

We would like to pass the 2 numbers to this macro and write the value in the excel book.

For R

Read More

Dingrui’s Useful VBA Scripts

This blog will be updated from time to time. Please check it regularly

Here are some useful VBA scripts (Macros in Excel).

You can download it through following links.

Please enable macro settings before using the following scripts.(Click this link for more information)

  1. Web Scraping Using VBA

This one calls the “IE” explorer in windows OS.(So if you are using Mac OS, please skip this one)
Please click correct button based on your location(Since chinese government blocks Google in mainland area)
It will pop up an IE window with a Google searching result page or a Baidu searching result page.

Read More