Consulting

Results 1 to 2 of 2

Thread: Combining selected work sheets into one

  1. #1
    VBAX Regular
    Joined
    Apr 2007
    Posts
    20
    Location

    Combining selected work sheets into one

    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/show...035#post104035

    Thanks a lot for all your time.

  2. #2
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,288
    Location
    Change the 2nd part of the code with this (not tried) : [VBA] '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[/VBA]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •