+ Reply to Thread
Results 1 to 2 of 2

Macro to insert column titles

Hybrid View

  1. #1
    Registered User
    Join Date
    02-22-2013
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    2

    Macro to insert column titles

    Hi,

    I'm new to writing macros and need a hand creating a macro to insert three column titles (first row, first three columns) on about 400 files!

    Sub Macro1()
    '
    '
    '



    '
    Selection.EntireRow.Insert
    Range("A1").Select
    ActiveCell.FormulaR1C1 = "Text"
    Range("B1").Select
    ActiveCell.FormulaR1C1 = "Text"
    Range("C1").Select
    ActiveCell.FormulaR1C1 = "Text"

    End Sub

    is what i have so far.. i'm just not sure how to write the code for an input folder and how to get it to go through all the files in the folder.
    thanks!
    Last edited by 0celj; 02-22-2013 at 09:25 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    02-12-2011
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    818

    Re: Macro to insert column titles

    If they are all in de same folder "Ocelj".
    Rename the folder settings.

    Sub WrkBksopen()
    Dim fileopen
    fileopen = Dir("C:\Users\HSV\Documents\Ocelj\*")
        Do Until fileopen = ""
          If fileopen = "" Then Exit Do
            Workbooks.Open "C:\Users\HSV\Documents\Ocelj\" & fileopen
            ActiveWorkbook.Sheets("Blad1").Range("A1").Resize(, 3) = Array("Title 1", "Title 2", "Title 3")
            Application.DisplayAlerts = False
            Workbooks(fileopen).Close True
         fileopen = Dir
        Loop
     Application.DisplayAlerts = True
    End Sub
    Kind regards, Harry.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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