+ Reply to Thread
Results 1 to 5 of 5

Macro to format data - counting and adding additional rows on condition

  1. #1
    Registered User
    Join Date
    08-31-2012
    Location
    HK
    MS-Off Ver
    Excel 2003
    Posts
    14

    Macro to format data - counting and adding additional rows on condition

    Hi,

    Have been working on a project requiring mathematical manipulation of data using R/SAS. For some functions the data need to be formatted correctly first, which I was hoping to achieve through a macro.

    Wanted to count the number of rows for each 'datekey' (column A) and if <14, then add additional rows with the same datekey until all are 14. Columns C:J on the inserted rows can remain blank (such that the mathematical procedures will omit these as corrupt data).

    Limited programming experience - any help pointing in the right direction greatly appreciated!

    Cheers

    sampledata.xls

  2. #2
    Registered User
    Join Date
    08-11-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Macro to format data - counting and adding additional rows on condition

    Hi,

    Try this code in the worksheet module:

    Please Login or Register  to view this content.
    Regards,

    Darzou

  3. #3
    Registered User
    Join Date
    08-31-2012
    Location
    HK
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: Macro to format data - counting and adding additional rows on condition

    excellent! there's an error with invalid use of 'me.' keyword

    but if i kill all the instances of 'me.' the code works perfectly

    thanks!

  4. #4
    Registered User
    Join Date
    08-11-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Macro to format data - counting and adding additional rows on condition

    The "Me" requires to use the code in the worksheet's module, not a stand alone module. Thus, if you select another worksheet or workbook while the program is still running there won't be any errors.

    Darzou

  5. #5
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Macro to format data - counting and adding additional rows on condition

    rynofrowan,

    Welcome to the Excel Forum.

    Thanks for the workbook.

    Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

    1. Copy the below code
    2. Open your NEW workbook
    3. Press the keys ALT + F11 to open the Visual Basic Editor
    4. Press the keys ALT + I to activate the Insert menu
    5. Press M to insert a Standard Module
    6. Where the cursor is flashing, paste the code
    7. Press the keys ALT + Q to exit the Editor, and return to Excel
    8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

    Please Login or Register  to view this content.
    Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

    Then run the AddAdditionalRows macro.
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Conditional Format - adding several data cells for one condition
    By JerBear in forum Excel - New Users/Basics
    Replies: 5
    Last Post: 05-01-2013, 09:47 AM
  2. [SOLVED] Adding additional rows to list in column
    By Markarmi in forum Excel General
    Replies: 2
    Last Post: 10-11-2012, 10:58 AM
  3. SUMProduct help counting # of records between 2 dates with additional condition
    By krichmond0306 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 09-12-2012, 02:48 PM
  4. Excel 2007 : adding additional rows
    By ccinorth in forum Excel General
    Replies: 1
    Last Post: 08-02-2011, 08:52 AM
  5. [SOLVED] Adding additional rows with formula
    By Mark in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-11-2006, 08:40 AM

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