+ Reply to Thread
Results 1 to 5 of 5

Macro to copy data under appropriate heading

  1. #1
    Registered User
    Join Date
    02-21-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    72

    Macro to copy data under appropriate heading

    Hi,

    I've attached a spreadsheet of what I'm working on. I have 2 tabs, "Sheet 1" (which is where I want to execute the macro) and "How it should look like" (after the macro has been executed).

    I'm trying to create a macro that copies range A18:A20 under the appropriate heading date in "Sheet1". For example, if the month is September 2013, I want it to copy the cells into C2:C3.

    You might ask why I'm not using a lookup function. The reason is that this is only a small scale example of what I'm working on. At the start of every new month, cell A17 is going to change, but I still want to be able to have previous months' records. So for example, in October, cell A17 will be October 2013, but I still want to keep September's values. Like I said, this is a really simplified example of what I'm working on.

    The script I'm working on is shown below. I've just started playing around with VBA a few days ago, so this is all sort of new to me. Any assistance as to what I'm doing wrong would be appreciated.
    Please Login or Register  to view this content.
    Thanks

    Sample.xlsx
    Last edited by anthony_91; 08-02-2013 at 08:38 PM.

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Macro to copy data under appropriate heading

    Bit long but
    Please Login or Register  to view this content.

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

    Re: Macro to copy data under appropriate heading

    anthony_91,

    Thanks for the workbook.

    Here is an update to your macro with code line explanations:

    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).

    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 CopyPasteV2 macro.



    The following macro is much faster because it does not loop thru the columns in row 1, one column at a time, and, it does some error checking.

    Range("A18:A20") does not contain formulae.

    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).

    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 CopyPasteV3 macro.
    Last edited by stanleydgromjr; 08-01-2013 at 10:50 AM.
    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.

  4. #4
    Registered User
    Join Date
    02-21-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    72

    Re: Macro to copy data under appropriate heading

    Quote Originally Posted by stanleydgromjr View Post
    anthony_91,

    Thanks for the workbook.

    Here is an update to your macro with code line explanations:

    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 CopyPasteV3 macro.
    Thank you so much. That worked perfectly.

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

    Re: Macro to copy data under appropriate heading

    anthony_91,

    You are very welcome. Glad I could help.

    Thanks for the feedback.

    And, come back anytime.

+ 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. macro help with Data list sorted by date then add a month Heading in between the sections
    By Researcher007 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-27-2013, 03:57 PM
  2. Macro to filter based on column heading then copy and paste to new sheet
    By macattackr in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-01-2012, 05:14 PM
  3. Code Problem Macro to copy specific cell based on the heading it is next to.
    By Mush1138 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-09-2011, 12:07 PM
  4. macro to find text heading then select underlying data?
    By excelRookie06 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-07-2011, 12:31 PM
  5. Copy data from different files into 1 workbook under relevant column heading.
    By novice81 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-18-2009, 01:19 AM

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