Solved

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

Posted on 2016-11-17
2
13 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
2 Comments
 
LVL 31

Accepted Solution

by:
Rob Henson earned 500 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
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 in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

708 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now