+ Reply to Thread
Results 1 to 2 of 2

Thread: Need help to tweak a macro so that it will format a plain csv file into a nice table

  1. #1
    Registered User
    Join Date
    11-24-2011
    Location
    SINGAPORE
    MS-Off Ver
    MS Office Home & Business 2010
    Posts
    9

    Need help to tweak a macro so that it will format a plain csv file into a nice table

    Hello, I have a problem.
    Our system automatically generates reports (tables) in the csv format only. It is very plain and ugly looking and does not have any formatting.

    I have used the macro recorder to record a macro so that when i click "Ctrl" and "K" it will format the data (several columns and several rows with the first row as the header) into a pre-program table in Excel.

    Here is the codes.

    I want to ask for help to tweak this code so that:-

    1) it will work for the current active (opened) CSV file regardless of the number of rows and the number of columns. I realised that when i record this macro, it is fixed rows and fix columns and if I use this macro for another csv file where there is less/more rows and less/more columns, the formatting of the table will not carry to these other rows


    2) I also need this csv file to be automatically saved into the latest Excel file format so that the formatting can be retained the next time this file is opened.

    Sub FORMATTABLE()
    '
    ' FORMATTABLE Macro
    ' This is to format csv into tables
    '
    ' Keyboard Shortcut: Ctrl+k
    '
        ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$BG$68"), , xlYes).Name = _
            "Table2"
        Range("Table2[#All]").Select
        ActiveSheet.ListObjects("Table2").TableStyle = "TableStyleLight6"
        Range("F11").Select
    End Sub
    Last edited by Leith Ross; 01-05-2012 at 02:23 AM. Reason: Added Code Tags

  2. #2
    Forum Guru TMShucks's Avatar
    Join Date
    07-15-2010
    Location
    Manchester, England
    MS-Off Ver
    MSO 2003 & 2007
    Posts
    6,230

    Re: Need help to tweak a macro so that it will format a plain csv file into a nice ta

    It may help to post a sample workbook with your code in place.

    Regards, TMS

+ 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.2.0