+ Reply to Thread
Results 1 to 17 of 17

Help, trying to create macro to add lines to current data

  1. #1
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Help, trying to create macro to add lines to current data

    Morning,

    Attached is the sample filtered data, what i need my macro to do is;

    - Prompt user to select network file
    - Once selected, filter data on 'A214' Hiport Fund
    - Use data on sheet 1 to populate sheet 2 but for each line on sheet 1 create 3 lines of data on sheet 2
    - Replace 'A214' on sheet 2 with 'A200', 'A210' & 'A220' on the 3 lines of data.
    - Keep original data on sheet 1.

    I hope anyone can help, i have been able to write code to promt the user for the file but now i'm struggling....

    Much appreciated
    Attached Files Attached Files
    Last edited by kenadams378; 07-24-2012 at 10:11 AM.

  2. #2
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Help, trying to create macro to add lines to current data

    Any code would be a start...

  3. #3
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Help, trying to create macro to add lines to current data

    How does the network file feature in the code?

    Do you mean to say the macro will be in an independent file, it needs to prompt the user to open the file. Once opened, the actions need to be performed?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  4. #4
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Help, trying to create macro to add lines to current data

    The file is located on a network drive, when the macro is started, the first prompt will be for the user to select the file they want to work with?

    The following steps will then commence

    ---------- Post added at 02:06 PM ---------- Previous post was at 02:02 PM ----------

    An independant sheet would be a good idea as the data will change each month...

  5. #5
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Help, trying to create macro to add lines to current data

    Once selected, filter data on 'A214' Hiport Fund
    Your sample data has data only for A214. Will there be other data too in the same file which is not A214?

    So ideally the steps should not be performed for data which is not equal to A214 right?

  6. #6
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Help, trying to create macro to add lines to current data

    All lines containing A214 need to be turned into the same data but over 3 lines;

    These will have A200,A210 & A220 as the 3 lines.

  7. #7
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Help, trying to create macro to add lines to current data

    I have done a manual version of what this should look like on sheet 2 attached.
    Attached Files Attached Files

  8. #8
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Help, trying to create macro to add lines to current data

    Try this code. It copies the whole data set, does a find replace for A200, then copies again and does a find replace for the A210 and then again for A220.
    Please Login or Register  to view this content.
    Copy the Excel VBA code
    Select the workbook in which you want to store the Excel VBA code
    Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
    Choose Insert | Module
    Where the cursor is flashing, choose Edit | Paste

    To run the Excel VBA code:
    Choose View | Macros
    Select a macro in the list, and click the Run button

  9. #9
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Help, trying to create macro to add lines to current data

    Hi, Thanks for theinput,

    I have added your code to mine but it doesn't do anything;

    Ideally, when the user selects the file, this would copy the orignal data to sheet1 then filter the same data by A214 then continue to insert 3 lines per A214

    My current code is below

    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Help, trying to create macro to add lines to current data

    Any further advice on this?!

  11. #11
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Help, trying to create macro to add lines to current data

    Oops i was working on this yesterday and had to rush out urgently, so couldnt finish it.

    Try this code
    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Help, trying to create macro to add lines to current data

    Wonderful, seems to work a treat, it is possible to keep the filter on A214 from the original data?

    ---------- Post added at 11:30 AM ---------- Previous post was at 11:26 AM ----------

    On top of that, woudl it be possible to have A200, A210 & A220 on seperate tabs and rename each tab Original Data, A200, A210 & A220?

  13. #13
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Help, trying to create macro to add lines to current data

    Yeah sure.

    You would like to keep the filter on the original tab even after the copy paste is done, right?

  14. #14
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Help, trying to create macro to add lines to current data

    Yep, then split the data across seperate named tabs, Original(filtered), A200, A210 & A220?

    Is it possible to copy to original data across to a new workbook before the macro does its work?

  15. #15
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Help, trying to create macro to add lines to current data

    Try this code. It performs all the actions including those given in post 14.
    Please Login or Register  to view this content.

  16. #16
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Help, trying to create macro to add lines to current data

    Thanks, that's great.

    I want to take the macro to add a few more bits of detail. do i need to start a new thread?

  17. #17
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Help, trying to create macro to add lines to current data

    Yes, you can quote the code given here if you want to make additions.

    ---------- Post added at 07:36 PM ---------- Previous post was at 07:35 PM ----------

    If you are satisfied with the solution(s) provided till here, please mark your thread as Solved.

    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

+ 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