PDA

View Full Version : Excell macro HELP PLEASE



Benvenuto
11-27-2008, 04:29 AM
Hello People,

At this moment I am using three worksheets. I found a very nice macro on this site. That when I insert a row in one sheet. That all worksheets will get this same row.

I would like that when I insert a row that when i put some text in the first sheet. It automatacly copies the content to the other worksheets.

I herby paste the macro I am allready using.

Option Explicit

Sub InsertRowAllSheets()

' Thanks to firefytr for the code that has been adapted into this routine

Dim cs As String
cs = ActiveSheet.Name
Dim y As Integer
y = Application.InputBox("Enter the row number you wish to add", _
Type:=1) 'enter 16 to insert a new row 16, the old row _
will become 17 And all other rows push down 1 row As well.
If MsgBox("Are you sure you wish to insert at row " & y & " for ALL sheets?", _
vbYesNo, "Insert row on ALL Sheets") = vbNo Then Exit Sub
Application.ScreenUpdating = False
Dim r As Range
Dim ws As Worksheet
' On Error Resume Next 'Error handler
For Each ws In ThisWorkbook.Worksheets
ws.Activate
Set r = ActiveSheet.Range("A" & y)
If y < 7 Then Goto circumv 'Not to insert in Headers
Range("A" & y).EntireRow.Insert

' code can be inserted here to copy formulas for some or all sheets in the workbook

circumv:
Next ws
Sheets(cs).Activate
Application.ScreenUpdating = True

End Sub


Thanks in advance.

Benvenuto

Bob Phillips
11-27-2008, 04:38 AM
Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit
Application.EnableEvents = False

With Target

.Copy Worksheets("Sheet2").Range(.Address)
.Copy Worksheets("Sheet3").Range(.Address)
End With

ws_exit:
Application.EnableEvents = True
End Sub


This is worksheet event code, which means that it needs to be
placed in the appropriate worksheet code module, not a standard
code module. To do this, right-click on the sheet tab, select
the View Code option from the menu, and paste the code in.

Benvenuto
11-27-2008, 06:40 AM
Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit
Application.EnableEvents = False

With Target

.Copy Worksheets("Sheet2").Range(.Address)
.Copy Worksheets("Sheet3").Range(.Address)
End With

ws_exit:
Application.EnableEvents = True
End Sub


This is worksheet event code, which means that it needs to be
placed in the appropriate worksheet code module, not a standard
code module. To do this, right-click on the sheet tab, select
the View Code option from the menu, and paste the code in.

Ok is it than olso possible to automaticly copy all what i put in. Into the other sheets???

P.s thank you for your prompt reply.