PDA

View Full Version : Combining selected work sheets into one



priya123
06-28-2007, 09:52 AM
Hi,

I took the help of the macro written by Lucas to combine mulitple work sheets.

Is there way to select only few of the work sheets and create a master instead of all the worksheets?

If yes please let me know how to do it.

The URL from which I took the macro is given below


http://www.vbaexpress.com/forum/showthread.php?p=104035#post104035

Thanks a lot for all your time.

Charlize
06-28-2007, 01:13 PM
Change the 2nd part of the code with this (not tried) : 'We can start loop
For Each sht In wrk.Worksheets
'If worksheet in loop is the last one, stop execution (it is Master worksheet)
If sht.Index = wrk.Worksheets.Count Then
Exit For
End If
If Worksheets(sht.Index).Name = "Name one" Or _
Worksheets(sht.Index).Name = "Name two" Then
'Data range in worksheet - starts from second row as first rows are the header rows in all worksheets
Set rng = sht.Range(sht.Cells(2, 1), sht.Cells(65536, 1).End(xlUp).Resize(, colCount))
'Put data into the Master worksheet
trg.Cells(65536, 1).End(xlUp).Offset(1).Resize(rng.Rows.Count, rng.Columns.Count).Value = rng.Value
End If
Next sht
'Fit the columns in Master worksheet
trg.Columns.AutoFit

'Screen updating should be activated
Application.ScreenUpdating = True