Copy Script from Sheet1 to Sheet2

Arcticwarrio

Active Member
Joined
Dec 6, 2005
Messages
439
Hello again all.
Probably a simple one this so i'll keep it short,

i have a sheet called Template with this code
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 2 And Target.Row = 2 Then
If Target.Cells.Count <> 1 Then Exit Sub
boo = Target.Value
boobs = Target.Offset(-1, 0).Value
nocold = 4
WO_update_cust
End If
If Target.Column = 2 And Target.Row = 3 Then
If Target.Cells.Count <> 1 Then Exit Sub
boo = Target.Value
boobs = Target.Offset(-2, 0).Value
nocold = 5
WO_update_cust
End If
End Sub

i have another script than unhides a sheet and copys whats in the template to it.

Simply put i want to copy this script to it too.

i used a copy and add sheet method but i need to be able to do this in a shared workbook, hence the hidden sheets instead.

thanks again.
Arctic.
 

Some videos you may like

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Arcticwarrio

Active Member
Joined
Dec 6, 2005
Messages
439
just incase your wondering what this strange script does heres the one it calls
Code:
Sub WO_update_cust()
Set Found = Nothing
PartNumber = boobs
FirstAddress = ""
If PartNumber = "" Then Exit Sub
With Worksheets("WORKSHOP")
Set Found = .UsedRange.Find(What:=PartNumber, LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=False)
If Not Found Is Nothing Then
FirstAddress = Found.Address
foundNum = foundNum + 1
rngNm = .Name
Worksheets(rngNm).Range(Found.Address(RowAbsolute:=False, ColumnAbsolute:=False)).Offset(, nocold).Value = boo
End If
End With
'If PartNumber = "" Then GoTo Stopitnow
If FirstAddress <> "" Then
If Not Range(Found.Address).Column = 1 Then GoTo Stopitnow
Else:
Stopitnow:
MsgBox ("error")
End If
Exit Sub
End Sub
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,230
Office Version
  1. 365
Platform
  1. Windows
It might help if you explained in words what the code is meant to do.

That would probably be more useful than us having us trying to interpret the code.:)
 

Arcticwarrio

Active Member
Joined
Dec 6, 2005
Messages
439
ok,
it a bit complicated to explain as the workbook has a lot of code.

i want to be able to copy the Worksheet_Change Sub from the TEMPLATE sheet to the selected sheet.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,230
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

Is it not possible to explain what the code is meant to do?

It really is hard to help without some sort of explanation.:)
 

Arcticwarrio

Active Member
Joined
Dec 6, 2005
Messages
439
here goes :)

on sheet "WORKSHEET"
when the next blank line is double clicked it added 1 to the number from above and unhides the next available worksheet and renames it to this number, then copies all the information from the sheet "TEMPLATE" and pastes it into this newly unhiden sheet.

the above works fine however i need to also copy the script from the TEMPLATE sheet so that when cell B2 or B3 is changed in the new sheet it finds the sheet number in the sheet "WORKSHEET" then it updates columns E and F.

does that help?
 

Arcticwarrio

Active Member
Joined
Dec 6, 2005
Messages
439

ADVERTISEMENT

i think i've just solved it, i just need to copy the code to all the hidden worksheets before the workbook is shared
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,230
Office Version
  1. 365
Platform
  1. Windows
Shared/hidden workbooks are just going to cause problems.:)

If you check Help you'll find a list of limitations of shared worksheets/workbooks.

Also, perhaps I'm missing something, but I still don't understand the code

If you want to copy a 'template' worksheet then why not just do that - the code should be copied as well.

Also if you are working with multiple worksheets, how about using a workbook level event rather than a worksheet event.:)
 

Arcticwarrio

Active Member
Joined
Dec 6, 2005
Messages
439
yeah i hate shared workbooks,
how would i impliment an on change event at workbook level?

thankss.
Arctic
 

Arcticwarrio

Active Member
Joined
Dec 6, 2005
Messages
439
Shared/hidden workbooks are just going to cause problems.:)

If you check Help you'll find a list of limitations of shared worksheets/workbooks.

Also, perhaps I'm missing something, but I still don't understand the code

If you want to copy a 'template' worksheet then why not just do that - the code should be copied as well.

Also if you are working with multiple worksheets, how about using a workbook level event rather than a worksheet event.:)

i couldnt get VBA to copy the TEMPLATE sheet while the workbook is shared so i made 100 hidden sheets
 

Watch MrExcel Video

Forum statistics

Threads
1,123,291
Messages
5,600,760
Members
414,405
Latest member
Zaurb

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
Top