?
Solved

How do I paste a macro from one spreadsheet to another.

Posted on 2016-11-17
2
Medium Priority
?
44 Views
Last Modified: 2016-11-17
We have a spreadsheet (97-2003) that some cells have a custom format of 0000-00-00
When you enter 1234, you get 1234-00-00 instead of 0000-12-34.
This is happening because of the following macro:

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.Count > 1 Then Exit Sub
    'modify the range A1:A20 to match your input cells
    If Not Intersect(Target, [j8:J46]) Is Nothing Then
        Application.EnableEvents = False
        Target.Value = Replace(Left(Target.Value & Space(8), 8), " ", "0")
        Application.EnableEvents = True
    End If
End Sub

How do I put this macro into a new spreadsheet to achieve the entry results?
 (I realize that the macro affects cells j8 through j46 and I will have to modify the cell range appropriately and use a macro-enabled workbook.)
0
Comment
Question by:Bill Golden
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 33

Accepted Solution

by:
Rob Henson earned 2000 total points
ID: 41891248
That is a Worksheet specific code. So, in the workbook that needs to receive the code, right click on the tab of the worksheet where you need the entries to change and select View Code. This will open the Visual Basic Editor and will show the code for that sheet. Copy and Paste into the "document" module pane on the right hand side.
0
 
LVL 1

Author Closing Comment

by:Bill Golden
ID: 41891420
That fixed it immediately.
Thanks
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question