Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default copy data to each worksheet

Hello:
I wrote a macro to copy one worksheet for each week of the year and name
each tab to each weeks date using Dataserial and it works fine. Now what I
need to do when some areas change on the worksheet is to be able to change it
on one and have the macro copy the changes to each worksheet. For example on
the timesheet when billing codes change that may be in range B2:B12 is to
have the macro copy that range onto each worksheet. please help.
--
He4Giv (Dick)
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default copy data to each worksheet

I know 2 ways:

1- having the comon data on a another sheet (kinda of database for prices)

2- using the change event of the thisworkbook module
Private Sub Workbook_SheetChange( _
ByVal Sh As Object, ByVal Target As Range)
' Sh is the changed sheet
' we will propagate to the other sheets
Dim S As Worksheet, cell As Range
For Each S In ThisWorkbook.Sheets
If S.Name < Sh.Name Then ' it's one of the other sheets
For Each cell In Sh.Range(Target.Address)
S.Range(cell.Address).Value = Sh.Range(cell.Address).Value
Next cell
End If
Next S
End Sub
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default copy data to each worksheet

SORRY I forgot a little detail:
(here the right code)

the point is that the macro change some cells and react when a cell is
changed - this is called an infinite loop. With this code we stop the
events while changing the cells, and reactivate events just after

Private Sub Workbook_SheetChange( _
ByVal Sh As Object, ByVal Target As Range)
' Sh is the changed sheet
' we will propagate to the other sheets
Application.EnableEvents = False
Dim S As Worksheet, cell As Range
For Each S In ThisWorkbook.Sheets
If S.Name < Sh.Name Then ' it's one of the other sheets
For Each cell In Sh.Range(Target.Address)
S.Range(cell.Address).Value = Sh.Range(cell.Address).Value
Next cell
End If
Next S
Application.EnableEvents = True
End Sub
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default copy data to each worksheet

Hi:
I may have said this wrong..I want to copy the data in range B2:B12 from
sheet 1 onto all the other worksheets. All 52 worksheets in this file are
exactly the same. they are timesheets that employees fill out weekly. At
times the reason codes change in the headers.
--
He4Giv (Dick)


"abcd" wrote:

SORRY I forgot a little detail:
(here the right code)

the point is that the macro change some cells and react when a cell is
changed - this is called an infinite loop. With this code we stop the
events while changing the cells, and reactivate events just after

Private Sub Workbook_SheetChange( _
ByVal Sh As Object, ByVal Target As Range)
' Sh is the changed sheet
' we will propagate to the other sheets
Application.EnableEvents = False
Dim S As Worksheet, cell As Range
For Each S In ThisWorkbook.Sheets
If S.Name < Sh.Name Then ' it's one of the other sheets
For Each cell In Sh.Range(Target.Address)
S.Range(cell.Address).Value = Sh.Range(cell.Address).Value
Next cell
End If
Next S
Application.EnableEvents = True
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default copy data to each worksheet

What do you mean ? You do not want "any" cell to be duplicated but only
a specific area in the Sheet1 ?

This does not change a lot of thing: just check first if the Target
(changed) cell is or is not in the wanted area. Then you also need to
put this code inside the Sheet1 (not in ThisWorkbook)


so the code (simplified) becomes:

Private Sub Worksheet_Change(ByVal Target As Range)
Const WantedAreas$ = "B2:B12"
If Not (Intersect(Target, Me.Range(WantedAreas$)) Is Nothing) Then
'propagate to other sheets
Application.EnableEvents = False
Dim S As Worksheet, cell As Range
For Each S In ThisWorkbook.Sheets
If S.Name < Me.Name Then ' it's one of the other sheets
S.Range(WantedAreas$).Formula = Me.Range(WantedAreas$).Formula
End If
Next S
Application.EnableEvents = True
End If
End Sub


now only a change in this area on Sheet1 will be propagated...
(Me represents the sheet where the code is written, so Sheet1)


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default copy data to each worksheet

Even shorter,
now we only detect from Sheet1, the macro will never call itself,
so we can write it shorter (no more need to stop the events inside the
macro). In Sheet1 vba code:

Private Sub Worksheet_Change(ByVal Target As Range)
Const WantedAreas$ = "B2:B12"
If Not (Intersect(Target, Me.Range(WantedAreas$)) Is Nothing) Then
'propagate to other sheets
Dim S As Worksheet, cell As Range
For Each S In ThisWorkbook.Sheets
If S.Name < Me.Name Then ' it's one of the other sheets
S.Range(WantedAreas$).Formula = Me.Range(WantedAreas$).Formula
End If
Next S
End If
End Sub
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy data from one worksheet to another LL Excel Worksheet Functions 5 December 14th 07 10:34 PM
copy from B worksheet to A worksheet with NO repeated data tikchye_oldLearner57 Excel Discussion (Misc queries) 1 September 29th 06 06:56 PM
copy data in a cell from worksheet A to worksheet B rajesh Excel Discussion (Misc queries) 1 February 21st 06 07:40 AM
Copy Modified Worksheet 1 Data to Worksheet 2 clarkelrc Excel Programming 0 April 15th 04 01:36 PM
copy all worksheet data into a new worksheet eric Excel Programming 2 October 2nd 03 08:33 PM


All times are GMT +1. The time now is 01:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"