Results 1 to 10 of 10

VBA to import used range of specific columns to different columns

Threaded View

  1. #1
    Forum Contributor Pierce Quality's Avatar
    Join Date
    07-29-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    221

    VBA to import used range of specific columns to different columns

    Hello All,
    Im looking for a way to import variable data from different columns in two different open workbooks to a master file. In the attached workbook I've given an example of the data in two different books on the Data1 and Data2 worksheets, and what the finished product should look like on the FinishedData sheet.
    The code I'm working with is this:

    Sub Data1()
    Dim wb As Workbook, x As String
    Dim ws As Worksheet
    
    For Each wb In Workbooks 'loop through all open workooks
     x = wb.Name
     If wb.Name <> ThisWorkbook.Name And wb.Name Like "*Book1*" Then
     Workbooks(x).Activate 'activate the workbook
     
    For Each ws In wb.Worksheets 'loop through all the worksheets in that workbook
        
      If ws.Name Like "*Sheet*" Then 'check if worksheet name contains Sheet
      ws.Range("A1").CurrentRegion.Offset(1).Copy _
      ThisWorkbook.Worksheets("Test").Range("A" & Rows.Count).End(xlUp).Offset(1)
      Workbooks(x).Close savechanges:=False
      End If
    Next
        
    End If
    Next wb
    
    End Sub
    and this:

    Sub Data2()
    Dim wb As Workbook, x As String
    Dim ws As Worksheet
    
    For Each wb In Workbooks 'loop through all open workooks
     x = wb.Name
     If wb.Name <> ThisWorkbook.Name And wb.Name Like "*Book2*" Then
     Workbooks(x).Activate 'activate the workbook
     
    For Each ws In wb.Worksheets 'loop through all the worksheets in that workbook
        
      If ws.Name Like "*Sheet*" Then 'check if worksheet name contains Sheet
      ws.Range("A1").CurrentRegion.Offset(1).Copy _
      ThisWorkbook.Worksheets("Test").Range("A" & Rows.Count).End(xlUp).Offset(1)
      Workbooks(x).Close savechanges:=False
      End If
    Next
        
    End If
    Next wb
    
    End Sub
    There are two different buttons to call each macro. Of course, the current code will copy ALL of the data, and I need it to only grab a specific set of columns, preferably without using the clipboard. In the actual master file, "Test" is the worksheet name the data is copied to.
    Any help would be greatly appreciated, Thanks!
    Attached Files Attached Files
    Last edited by Pierce Quality; 02-13-2014 at 01:29 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Import specific columns past a certain row into another spreadsheet.
    By Nexion21 in forum Excel General
    Replies: 4
    Last Post: 08-10-2013, 08:49 PM
  2. How to import specific columns from excel file
    By Drehb4life in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-26-2013, 12:55 PM
  3. Macro to import data from specific columns form csv and rearrange
    By tonyrobbo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-21-2013, 02:01 PM
  4. vba only import columns from csv with specific text in row A
    By CuvelieY in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-17-2011, 09:41 AM
  5. import data to specific columns
    By marlea in forum Excel General
    Replies: 1
    Last Post: 08-11-2005, 10:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1