Solved

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

Posted on 2016-11-17
2
31 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 33

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

735 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