Results 1 to 2 of 2

How to read headers from closed file and paste it in new sheet as column using VBA

Threaded View

  1. #1
    Registered User
    Join Date
    06-22-2016
    Location
    Pune
    MS-Off Ver
    2010
    Posts
    14

    How to read headers from closed file and paste it in new sheet as column using VBA

    Hello,
    I have 10+ files in a folder. i wants to copy all files headers to new sheet as a column. i am able to do this . But i wants to copy file name and sheet name also i tried but not getting data.
    plz see the attchments.
    C1.JPG

    Below is my code:
    Public Sub CommandButton1_Click()
    'DECLARE AND SET VARIABLES
    Dim wbk As Workbook
    Dim Filename As String
    Dim Path As String
    Dim mainwb As Workbook
    Dim ws As Worksheet
     Dim search_result As Range   'range search result
        Dim blank_cell As Long
    Dim wb As Workbook
    'Path = "C:\Test\Input\"
    'Filename = Dir(Path & "*.xls")
    Workbooks("abc.xlsm").Activate
    input_directory = Sheets("SystemConfiguration").Range("B2").Value & "\"
     Filename = Dir(input_directory & "*.xls")
    
    '--------------------------------------------
    'OPEN EXCEL FILES
     Do While Len(Filename) > 0  'IF NEXT FILE EXISTS THEN
        Set wbk = Workbooks.Open(input_directory & Filename)
        'MySheet = Application.Caller.Worksheet.Name
        'Set sh = MySheet()
       'Variable = ActiveSheet.Name
      ' Sheets(Variable).Range("A1:D1").Copy
        'Sheets("Sheet2").Column(B2).Select.Activate.Paste
       ' Sheets("Sheet2").Active
        'Columns("B2").Select
      Set wbk = ActiveWorkbook
      Filename = ActiveWorkbook.Name
      Variable = ActiveSheet.Name
     ' wbk.Sheets(Variable).Rows(1).EntireRow.Copy
     ActiveSheet.UsedRange.Rows(1).Copy
    
     Workbooks("newfile.xlsm").Activate
    'ActiveWorkbook.ActiveSheet
     Set wb = ActiveWorkbook
      Set ws = wb.Sheets("Sheet1")
      
        For Each cell In ws.Columns(7).Cells
            If IsEmpty(cell) = True Then cell.Select: Exit For
        Next cell
     Selection.PasteSpecial Paste:=xlPasteValues, Transpose:=True
     
    ' Selection.PasteSpecial Paste:=xlPasteValues, Transpose:=True
        wbk.Close savechanges:=False
        Filename = Dir
    Loop
    End Sub
    Last edited by Amar321; 06-27-2016 at 03:31 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. VBA Excel: Copy/Paste a column range to another sheet IF column headers match
    By hwatson86 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 06-07-2016, 08:05 AM
  2. [SOLVED] read single cell content from sheet of closed file and put it in a cell on an active sheet
    By rsmith5413 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-09-2014, 04:16 AM
  3. [SOLVED] Match value(s) in column with headers of another sheet and paste a cell value from column
    By Zoediak in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-17-2013, 11:34 AM
  4. copy sheet and paste into sheet in closed file
    By chichaspowa in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-01-2013, 06:10 PM
  5. Open file, new column, vlookup, copy paste, closed
    By dare2join in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-30-2013, 09:59 PM
  6. [SOLVED] Read whole file,Match the headers based on specific condition & write to text file
    By macromaniac in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 06-07-2011, 06:37 AM
  7. Using ADO to read closed file does not read formulas
    By treyr in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-09-2010, 12:26 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