74 lines
1.4 KiB
Markdown
74 lines
1.4 KiB
Markdown
---
|
|
id: excel-macros
|
|
aliases: []
|
|
tags:
|
|
- destiny/permanent
|
|
- status/draft
|
|
- topic/software
|
|
- type/guide
|
|
title: Excel Macros
|
|
---
|
|
# Excel Macros
|
|
|
|
Excel macros are a poor solution for most problems,
|
|
however some simple formatting motions are a good fit.
|
|
|
|
This document is a step-by-step process for implementing such a macro,
|
|
assuming a fresh Excel install.
|
|
|
|
## 1. Enable Developer Tools
|
|
|
|
```menu
|
|
File > Options > Customize Ribbon
|
|
```
|
|
|
|
On the right side, under `Main Tabs`, check `Developer`.
|
|
|
|
## 2. Create `PERSONAL.XLSB`
|
|
|
|
```menu
|
|
Developer > Code > Record Macro
|
|
```
|
|
|
|
Set `Store macro in:` to `Personal Macro Workbook`
|
|
and click `OK`, then `Stop Recording`.
|
|
|
|
## 3.
|
|
|
|
```menu
|
|
Developer > Visual Basic
|
|
```
|
|
|
|
In the pop-up window, navigate to and double-click
|
|
"VBAProject (PERSONAL.XLSB)/Modules/Module1"
|
|
|
|
Erase the empty macro created in step 2
|
|
and add desired macros here.
|
|
My favorite is provided below.
|
|
|
|
```vb
|
|
Sub FillDownEmptyCells()
|
|
Dim rng As Range
|
|
Dim cell As Range
|
|
|
|
' Check if a range is selected
|
|
If Selection Is Nothing Then
|
|
Exit Sub
|
|
End If
|
|
|
|
' Set the selected range
|
|
Set rng = Selection
|
|
|
|
For Each cell In rng
|
|
If IsEmpty(cell.Value) Then
|
|
' Copy cell above to empty cell
|
|
cell.Value = cell.Offset(-1, 0).Value
|
|
End If
|
|
Next cell
|
|
|
|
End Sub
|
|
```
|
|
|
|
Use `Ctrl+S` or the save icon to save the edits
|
|
then close the Visual Basic window.
|