You are here:

Excel/Excel VBA: merged data and copy, paste, values(2)


I wasn't able to add an additional follow-up questions to previous thread so I posted a new item. Hope that's ok.

From each task worksheet it would start at A2, would include columns A thru and including O, and the number of rows may vary on each tasks worksheet. Basically it would work if starting from A2 and you did a Cntrl>Sht>End but only included columns A thru O.

Hi Mark,

In that case, this should suffice:

Sub Combine()
   Dim ws As Worksheet
   Dim lCols As Long
   On Error Resume Next
   On Error GoTo 0

   ' copy headings
   Selection.Copy Destination:=Sheets(1).Range("A1")

   ' work through sheets
   For Each ws In Worksheets
       If LCase(ws.Name) Like "*tasks*" Then
         lCols = ws.UsedRange.Columns.Count
         'no further than col. O
         If lCols > 15 Then lCols = 15
         With Worksheets("Combined")
         .Range("A" & .Rows.Count).End(xlUp).Offset(2).Resize(ws.UsedRange.Rows.Count, lCols).Value = _
         Intersect(ws.Range("A:O"), ws.UsedRange).Value
         End With
       End If

   Range("P:DT").Delete Shift:=xlToLeft

End Sub  
About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here


All Answers

Answers by Expert:

Ask Experts


Jan Karel Pieterse


Excel and Excel/VBA questions


Excel MVP

Self employed Excel developer

Bachelor in Chemical Engineering

Awards and Honors
Microsoft MVP award since 2002

Past/Present Clients
Shell, Fortis bank, ABN-AMRO bank, Morgan Stanley, ...

©2017 All rights reserved.