VBA Macro used in the Microsoft Office Excel Application

Excel Copy Cell Above or Below | VBA Macro #14

Share on facebook
Share on twitter
Share on linkedin
Have you run into this problem? You are completing an export of records with a variety of items some of them having multiple lines of values. After completing your export, you realize there are blank rows that should have the values of the cells above or below. Which is extremely frustrating if the unique identifier is missing values that it should be associated with. A situation like this can leave you wondering “Now what?” This is why Leverage & Lean created the Copy Cell Above or Below macro that can assist you with populating all of these empty cells. Once you run this Excel macro an InputBox will appear to determine if you want the cell values from above or below the blank cells. Indicate your selection with a 1 or 2 then watch at the blank cells transform into their appropriate values. (This macro is customizable allowing you to default either the Above or Below cell avoiding the InputBox altogether)

See it in Action!

Watch this video to see this macro in action.

The Code

Here is the code behind this macro.
'Leverage & Lean "Less Clicks, More Results"
Sub CopyCellAboveBelow()
' Means variable is in use
Dim AboveorBelow As String '
Dim BelowCounter As Integer '
Dim Column As Integer '
Dim LastColumn As Integer '
Dim LastRow As Integer '
Dim Row As Integer '
On Error GoTo LeverageLean

'Determine if you want to copy the cell from Above or Below
AboveorBelow = InputBox("Do you want to copy the cell from Above or Below?" & vbNewLine & _
         "1. Copy Cell Above" & vbNewLine & _
         "2. Copy Cell Below")

'AboveorBelow = 1 'Default to copy cell from Above
'AboveorBelow = 2 'Default to copy cell from Below

If AboveorBelow = "" Then
Exit Sub
ElseIf AboveorBelow <> 1 And AboveorBelow <> 2 Then
MsgBox ("Please select a valid response 1 or 2.")
Exit Sub
End If
Row = 1
Column = 1
LastRow = Cells(Rows.Count, 1).End(xlUp).Row 'Identify Last Row on worksheet
LastColumn = Cells(Row, Columns.Count).End(xlToLeft).Column 'Identify Last Column on worksheet

Do Until Row > LastRow
Do Until Column > LastColumn
If Cells(Row, Column).Value = "" Then 'If Cell is Blank determine what cell to copy
If AboveorBelow = 1 Then 'Copy Cell Above
If Cells(Row - 1, Column).Value <> "" Then
Cells(Row, Column).Value = Cells(Row - 1, Column).Value
End If
ElseIf AboveorBelow = 2 Then 'Copy Cell Below
BelowCounter = 1
Do Until Cells(Row, Column).Value <> ""
If Cells(Row + BelowCounter, Column).Value <> "" Then
Cells(Row, Column).Value = Cells(Row + BelowCounter, Column).Value
End If
BelowCounter = BelowCounter + 1
End If
End If
Column = Column + 1
Column = 1
Row = Row + 1


MsgBox ("Copy Cell from Above or Below is complete!  Stay Awesome!")
Exit Sub

MsgBox ("Something went wrong.  Don't hesitate to email me: brentschneider@leveragelean.com")

End Sub
'Stay Awesome

Macro Monday

Here is the Macro Monday video this macro was featured in. Watch this video to learn how to get the most out of this macro and start using it today!


These lines of code can be customized to personalize this macro.

14, 18 and 19 Here is where you can make the InputBox a comment and instead default running the Above or Below portion of this code.

58 If you don’t want to see a finished MsgBox you can make it a comment or delete it here.
Notify of
Inline Feedbacks
View all comments

Search for Excel Macros

Recent Macros

VBA Macro used in the Microsoft Office Outlook Application

Outlook Send Same Email to Different Recipients | VBA Macro #31

To BCC or to not BCC?  That is the question that comes to mind when emailing a variety of different recipients.  This is especially important if you are working with multiple clients.  You can BCC recipients so they can’t click reply all. Recipients won’t see who was emailed but that is actually the problem.  The value is knowing who was emailed so customers know if additional follow-up is needed.  Instead you can CC recipients but once someone hits Reply All the conversation can get out of control.  This can create a bigger problem if the email thread is across multiple parties. Sending separate emails creates more value for the customer but how do you do this efficiently and effectively? You could create new emails do a lot of copying and pasting but this isn’t a sustainable process. Good news is there is always a better way with VBA! Our new Outlook macro makes sending the same email to different recipients so easy!

VBA Macro used in the Microsoft Office Excel Application

Excel Find and Replace across Multiple Word Documents | VBA Macro #30

Say a company rebranded and changed locations.  How would you handle updating all the necessary internal documents with the new company name, address, phone number, and email address? This can be a massive undertaking for any company which is why we created the Excel Find and Replace across Multiple Word Documents macro! This is an Excel macro that will Find and Replace values in Multiple Word Documents. This Excel macro is a great way to maintain Word Documents that are routinely changing information.

VBA Macro used in the Microsoft Office Word Application

Word Create Outlook Email with Selected Text | VBA Macro #29

Have you ever been prompted to send a follow up email while working in Word?  Maybe you are reviewing a meeting agenda or reading a final draft for a new company policy. You can navigate to Outlook create a new email and copy paste the necessary text in.  This takes a bit of time and isn’t very efficient.  Instead try using our Word Macro Create Outlook Email with Selected Text!  This macro will generate an Outlook email directly out of Word pulling in any text you have selected into the Email Body.  This macro is a better way to generate a follow up email helping you get a quicker response. Instead of writing reminders on Post-it notes start using this macro Create Outlook Email with Selected Text today!

First time using VBA?

The Developer Tab is an additional section of the ribbon when activated allows you access to Visual Basic in Applications like Excel, Outlook, Word.
Setup Now
Once the Developer Tab is available you will have the capability to update your security to allow Macros to run in the current application.
Setup Now
A sub of code is a collection of objects and variables. For the code to successfully run a library of references needs to be set.
Setup Now

Looking for more?

Subscribe as an Insider to receive additional rights.

Contact Us

Looking to improve your computer processes?
Leverage & Lean is here to help!

Copyright © 2019 Leverage & Lean – Uptown Style WordPress theme by GoDaddy