PC Review


Reply
Thread Tools Rate Thread

Collate data

 
 
Rachel
Guest
Posts: n/a
 
      20th Nov 2008
Hi,

I am using the following macro code to copy each worksheet to a master file
worksheet. However, with this macro code, it copies the whole worksheet to
the master file. I want to put a constant column in my master file in such a
way that when i run the macro to collate the column which i placed on the
summary file will not be erased. Anyone who could help? thanks

I only want that it copies column A:L only but when I changed column below
to A:L it still copies the whole worksheet.

Sub ColateData()

Dim Dsheet As Worksheet, Ssheet As Worksheet
Dim addrow As Long, lastrow As Long
Dim source As Range, dest As Range

Application.ScreenUpdating = False
ThisWorkbook.Sheets("Summary").Select
Set Ssheet = ThisWorkbook.Sheets("Summary")
With Ssheet
lastrow = Cells(Rows.Count, 1).End(xlUp).Row
If lastrow = 1 Then lastrow = 2
Rows("3:" & lastrow).Clear
End With

For Each Dsheet In Worksheets
With Ssheet
lastrow = Cells(Rows.Count, 1).End(xlUp).Row
End With

If Dsheet.Name <> "Summary" Then
addrow = Dsheet.Cells(Rows.Count, 1).End(xlUp).Row
Set source = Dsheet.Range("A2:L" & addrow)
Set dest = Ssheet.Range("A" & lastrow + 1)
source.Copy dest
End If
Next

Application.ScreenUpdating = True
End Sub
 
Reply With Quote
 
 
 
 
Max
Guest
Posts: n/a
 
      21st Nov 2008
Try replacing this line:
> Rows("3:" & lastrow).Clear


with this:
Range("A3:L" & lastrow).Clear

The former line clears entire rows from row3 down to lastrow (in Summary),
while the replacement line clears only cols A:L from row3 down to lastrow.
Hence this will preserve what you may have set up in cols to the right of col
L.
--
Max
Singapore
http://savefile.com/projects/236895
Downloads:20,500 Files:363 Subscribers:64
xdemechanik
---
"Rachel" wrote:
> I am using the following macro code to copy each worksheet to a master file
> worksheet. However, with this macro code, it copies the whole worksheet to
> the master file. I want to put a constant column in my master file in such a
> way that when i run the macro to collate the column which i placed on the
> summary file will not be erased. Anyone who could help? thanks
>
> I only want that it copies column A:L only but when I changed column below
> to A:L it still copies the whole worksheet.
>
> Sub ColateData()
>
> Dim Dsheet As Worksheet, Ssheet As Worksheet
> Dim addrow As Long, lastrow As Long
> Dim source As Range, dest As Range
>
> Application.ScreenUpdating = False
> ThisWorkbook.Sheets("Summary").Select
> Set Ssheet = ThisWorkbook.Sheets("Summary")
> With Ssheet
> lastrow = Cells(Rows.Count, 1).End(xlUp).Row
> If lastrow = 1 Then lastrow = 2
> Rows("3:" & lastrow).Clear
> End With
>
> For Each Dsheet In Worksheets
> With Ssheet
> lastrow = Cells(Rows.Count, 1).End(xlUp).Row
> End With
>
> If Dsheet.Name <> "Summary" Then
> addrow = Dsheet.Cells(Rows.Count, 1).End(xlUp).Row
> Set source = Dsheet.Range("A2:L" & addrow)
> Set dest = Ssheet.Range("A" & lastrow + 1)
> source.Copy dest
> End If
> Next
>
> Application.ScreenUpdating = True
> End Sub

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
collate data Vlookup? BimboUK Microsoft Excel Misc 1 24th Jul 2009 03:31 PM
Collate data from many workbooks =?Utf-8?B?Y2d5?= Microsoft Excel Misc 2 23rd Nov 2007 07:17 PM
How do I collate (match-up) one column's data with another? =?Utf-8?B?TWFyaw==?= Microsoft Excel Worksheet Functions 2 16th Mar 2006 04:21 PM
Word documents won't collate, even though collate box is checked. =?Utf-8?B?Ymxub3J3b29k?= Microsoft Word Document Management 1 30th Mar 2005 09:51 AM
How do I search a data range for a particular value then collate . =?Utf-8?B?SHVsa2FzY29vYnk=?= Microsoft Excel Misc 0 19th Jan 2005 03:21 PM


Features
 

Advertising
 

Newsgroups
 


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