Excel

Paste Special: Add - User Defined

Ease of Use

Intermediate

Version tested with

2000/XP 

Submitted by:

Zack Barresse

Description:

A user-defined amount to Paste Special: Add on an entire selection. 

Discussion:

Often when you need to add an entire selection of formulas by the same amount (e.g. add 1500) you would need to find a blank cell, type in a number (e.g. 1500), copy it, re-select your range, Paste Special: Add. With this you need not do any of that. Just enter the amount to add and let the code handle the rest. 

Code:

instructions for use

			

Option Explicit Sub psAdd() Dim y As Integer 'The multiplier value, user-defined Dim x As Range 'Just a blank cell for variable Dim z As Range 'Selection to work with Set z = Selection y = Application.InputBox("Enter amount to add to selection:", _ Title:="Add to selection", Default:=10, Type:=1) Set x = Range("A65536").End(xlUp).Offset(1) If y = 0 Then Exit Sub 'Cancel button will = 0, hence cancel If x <> "" Then Exit Sub Else: x.Value = y x.Copy z.PasteSpecial Paste:=xlPasteAll, Operation:=xlAdd Application.CutCopyMode = False 'Kill copy mode End If x.ClearContents 'Back to normal : ) End Sub

How to use:

  1. Copy the above code.
  2. Open any workbook.
  3. Press Alt + F11 to open the Visual Basic Editor (VBE).
  4. From the Menu, choose Insert-Module.
  5. Paste the code into the right-hand code window.
  6. Close the VBE, save the file if desired.
 

Test the code:

  1. Tools-Macro-Macros, and double-click psAdd
 

Sample File:

psAdd.zip 7.34KB 

Approved by mdmackillop


This entry has been viewed 149 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express