copy a worksheet and function

colinharwood

Active Member
Joined
Jul 27, 2002
Messages
426
Office Version
  1. 2019
Platform
  1. Windows
Hi
After copying a worksheet which contains a function to a new workbook, the function disappears from the worksheet, is there a way to overcome this.
Thanks a lot

This is the worksheet code:

Private Sub Worksheet_Activate()
ActiveWindow.SmallScroll Down:=-96
Range("A3").Select

End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Cells.Interior.ColorIndex = xlNone
With Cells(ActiveCell.Row, 1).Resize(1, 21).Interior
.ColorIndex = 40
.Pattern = xlSolid
End With
rowOffset = -4



End Sub

Function AddSpace(Str As String) As String
Dim i As Long
For i = 1 To Len(Str)
AddSpace = AddSpace & Mid(Str, i, 1) & " "
Next i
AddSpace = Trim(AddSpace)
End Function
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
If you are just copying the sheet to a new workbook, only that data on the sheet is copied over. VBA code is NOT copied over.
Why not make a copy of the file itself? Then the new file will have all of that in there. If there are pages you don't need, just delete them after the file copy.
You code do all of that with VBA code (do a file copy and delete sheets).
 
Upvote 0
Is it possible you could make the function into a Macro and copy the Module over to the other workbook, may not be the ideal solution but should work.
 
Upvote 0
Thanks for the suggestions.
I dont think that there is any way to save it as a Macro, so I'll look into saving whole file and then deleting sheets
Thanks
 
Upvote 0
Are you copying the entire sheet, or just the cells?
Also is the other workbook an xlsm workbook?
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,868
Members
449,053
Latest member
Mesh

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top