Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8
Default macro error - copying data twice

I have the following macro (created with this board's help!) that works well,
except it copies each sheet's data to the master twice. Can anyone tell me
what to change so that it only copies the data from each sheet once?

Many thanks!
Gretta

Sub Test5()
Dim sh As Worksheet
Dim DestSh As Worksheet
Dim shLast As Long
Dim Last As Long

' copies each sheets contents to master sheet

On Error Resume Next
If Len(ActiveWorkbook.Worksheets.Item("Master").Name) = 0 Then
On Error GoTo 0
Application.ScreenUpdating = False
Set DestSh = ActiveWorkbook.Worksheets.Add
DestSh.Name = "Master"
For Each sh In ActiveWorkbook.Worksheets
If Not IsError(Application.Match(sh.Name,
Worksheets("MySheets").Range(Worksheets _
("MySheets").Cells(1, "A"),
Worksheets("MySheets").Cells(Rows.Count, _
"A").End(xlUp)), 0)) Then
Last = LastRow(DestSh)
shLast = LastRow(sh)
sh.Range(sh.Rows(6), sh.Rows(shLast)).Copy
With DestSh.Cells(Last + 1, "A")
.PasteSpecial xlPasteValues, , False, False
.PasteSpecial xlPasteFormats, , False, False
.PasteSpecial 8, , False, False
Application.CutCopyMode = False
End With
End If
Next
DestSh.Cells(1).Select
Sheets("Accounting").Select
Rows("5:5").Select
Selection.Copy
ActiveWindow.ScrollWorkbookTabs Position:=xlLast
Sheets("Master").Select
Rows("1:1").Select
Selection.Insert Shift:=xlDown
Application.ScreenUpdating = True
Else
MsgBox "The sheet Master already exist"
End If
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,355
Default macro error - copying data twice

I'd guess it was related to your two paste special lines. Why don't you step
through the macro line by line and see where it happens.

"Gretta" wrote:

I have the following macro (created with this board's help!) that works well,
except it copies each sheet's data to the master twice. Can anyone tell me
what to change so that it only copies the data from each sheet once?

Many thanks!
Gretta

Sub Test5()
Dim sh As Worksheet
Dim DestSh As Worksheet
Dim shLast As Long
Dim Last As Long

' copies each sheets contents to master sheet

On Error Resume Next
If Len(ActiveWorkbook.Worksheets.Item("Master").Name) = 0 Then
On Error GoTo 0
Application.ScreenUpdating = False
Set DestSh = ActiveWorkbook.Worksheets.Add
DestSh.Name = "Master"
For Each sh In ActiveWorkbook.Worksheets
If Not IsError(Application.Match(sh.Name,
Worksheets("MySheets").Range(Worksheets _
("MySheets").Cells(1, "A"),
Worksheets("MySheets").Cells(Rows.Count, _
"A").End(xlUp)), 0)) Then
Last = LastRow(DestSh)
shLast = LastRow(sh)
sh.Range(sh.Rows(6), sh.Rows(shLast)).Copy
With DestSh.Cells(Last + 1, "A")
.PasteSpecial xlPasteValues, , False, False
.PasteSpecial xlPasteFormats, , False, False
.PasteSpecial 8, , False, False
Application.CutCopyMode = False
End With
End If
Next
DestSh.Cells(1).Select
Sheets("Accounting").Select
Rows("5:5").Select
Selection.Copy
ActiveWindow.ScrollWorkbookTabs Position:=xlLast
Sheets("Master").Select
Rows("1:1").Select
Selection.Insert Shift:=xlDown
Application.ScreenUpdating = True
Else
MsgBox "The sheet Master already exist"
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
macro error - copying data twice Gretta Excel Discussion (Misc queries) 1 April 6th 07 04:40 PM
Macro for copying conditional data ipsy9 Excel Worksheet Functions 0 June 8th 06 08:19 PM
Getting error "selection is too large" when copying data Tootie Excel Discussion (Misc queries) 1 October 6th 05 12:19 AM
Getting error "selection is too large" when copying data Tootie Excel Discussion (Misc queries) 0 October 5th 05 08:42 PM
Macro Help - Copying and appending data Louis Markowski Excel Worksheet Functions 1 September 16th 05 06:53 PM


All times are GMT +1. The time now is 07:06 PM.

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"