+ Reply to Thread
Results 1 to 15 of 15

Repeat simple Macro

  1. #1
    Registered User
    Join Date
    07-28-2014
    Location
    California
    MS-Off Ver
    2010
    Posts
    8

    Repeat simple Macro

    I am trying to copy values from cells B3:N3 into cells E2:Q2, and then delete row 3. Then I'd like to repeat this for the entire worksheet until the rows are empty.

    I have a simple macro to cut/paste and delete, but I know there is a better way to do this when it involves several rows. Can anyone help me understand how to repeat this?

    Please Login or Register  to view this content.
    Thank you in advance for your help.
    Last edited by alansidman; 07-28-2014 at 10:14 PM. Reason: code tags added

  2. #2
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Repeat simple Macro

    Hi,

    Try this (untested):
    Please Login or Register  to view this content.
    I hope this helps

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2507 Win 11
    Posts
    24,920

    Re: Repeat simple Macro

    Kristina

    Code Tags Added
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (Because you are new to the forum, I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  4. #4
    Registered User
    Join Date
    07-28-2014
    Location
    California
    MS-Off Ver
    2010
    Posts
    8

    Re: Repeat simple Macro

    Hi Alan,

    My apologies, and thank you. I have now read all of the rules

    ajryan88 - thank you very much, too. I tried it, but receive an error '438' - Object doesn't support this property method. Any ideas? I have attached the workbook. It is in the "RemoveWrap" Sub. Basically, the program that is spitting out my .csv/Excel file is for some reason inserting an inadvertent line wrap after the city/state (cells D2, D4, etc.) and the values that start at B3, B5, etc are supposed to be up in the E2, E4, etc cells. The programmers have confirmed that this is a bug in the original program so I'm trying to use Excel to fix it. I am a total newbie when it comes to excel macros and VBA, but am very interested in learning. I've tried all sorts of google searches, but have a hard time translating other solutions to my specific need. Your help is extremely appreciated!
    Attached Images Attached Images

  5. #5
    Registered User
    Join Date
    07-28-2014
    Location
    California
    MS-Off Ver
    2010
    Posts
    8

    Re: Repeat simple Macro

    I meant to remove the attached image per forum rules and attach the workbook itself. However, I don't see a paper clip to attach a file. Only links, images, quotes, etc.

    The attached image is all I see: ForumPost.jpg
    Last edited by KristinaG; 07-29-2014 at 03:39 PM.

  6. #6
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Repeat simple Macro

    To attach a file, click on Go Advanced (bottom-right of the Quick Reply window), and then Manage Attachments

  7. #7
    Registered User
    Join Date
    07-28-2014
    Location
    California
    MS-Off Ver
    2010
    Posts
    8

    Re: Repeat simple Macro

    Ah, thank you. WithLocation.xlsm

  8. #8
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Repeat simple Macro

    Sorry, the reason it isn't working is my fault...I accidentally pasted the wrong code above. The Paste method is a worksheet method, not a range method. Use this code instead and you should be all sweet:
    Please Login or Register  to view this content.
    Let me know how you get on

  9. #9
    Registered User
    Join Date
    07-28-2014
    Location
    California
    MS-Off Ver
    2010
    Posts
    8

    Re: Repeat simple Macro

    Thank you!!! It ran without an error, but there was still something strange going on with the rows. I realized it was because the row needs to be deleted after the B:N cells are cut. So I experimented with a few things and finally got it to work perfectly! I appreciate your help so much, I would have never known how to get it started and I learned a little along the way.

    The only thing I need now is to apply it to ALL worksheets/tabs in the excel file. How would I do that? Something like "With ThisWorkbook.Worksheets("All")?

    This is what I ended up using (same as yours, except with the delete row command). Is that how you would have gone about it?

    Please Login or Register  to view this content.

  10. #10
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Repeat simple Macro

    Sorry, I thought when you said "delete rows" in your OP you meant "clear the contents", but after seeing the actual format of your data from your attachment above, I realise that you actually meant "delete rows".

    To do this for all worksheets, use the following code (I have started with your code from the previous post, altered the way in which rows are deleted, and added the worksheet loop):
    Please Login or Register  to view this content.
    I changed the way the entire row is deleted because it isn't necessary to select a cell/range to delete it, and your code will run faster if you don't select everything before operating on it -- you will notice that I made similar changes from your original code to get to the code that I pasted above...

    I hope this helps

  11. #11
    Registered User
    Join Date
    07-28-2014
    Location
    California
    MS-Off Ver
    2010
    Posts
    8

    Re: Repeat simple Macro

    You are very kind for helping. Thank you

    I'm noticing now that the last range of cells to be cut/pasted are actually gone (see image 1). Also, there is an error "1004" after it completes the first worksheet.

    I've attached a workbook that has two worksheets for you to experiment with if you'd like.

    image1.jpg
    Test.xlsx

  12. #12
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Repeat simple Macro

    This code will fix your error 1004...
    Please Login or Register  to view this content.
    As for the last row going missing...let me have a look into it and I'll get back to you...

    EDIT: I have just successfully run this code with 2 worksheets no dramas, so let me know how you go
    Last edited by ajryan88; 07-29-2014 at 08:39 PM.

  13. #13
    Registered User
    Join Date
    07-28-2014
    Location
    California
    MS-Off Ver
    2010
    Posts
    8

    Re: Repeat simple Macro

    Works beautifully! You're the best Many, many thanks to you.

  14. #14
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Repeat simple Macro

    No worries

    Please don't forget to mark this thread as solved (Thread Tools --> Mark As Solved), and please click on the * next to my post to say thanks

  15. #15
    Registered User
    Join Date
    07-28-2014
    Location
    California
    MS-Off Ver
    2010
    Posts
    8

    Re: Repeat simple Macro

    Done! (thanks for showing me). Do you mind if I post the code on my blog? It will help architects who want to use 3ds Max Design for daylighting analysis. 3ds Max Design is the program that exports out the CSV files with the extra line wrap in the data.

    My blog: http://bimchicks.com

+ 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. Repeat a simple macro in excel
    By Alexander_Hinkov in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-31-2014, 03:41 AM
  2. Replies: 4
    Last Post: 03-08-2014, 08:01 AM
  3. [SOLVED] Macro - Repeat macro a specific number of times
    By uvinduds in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-25-2013, 02:42 PM
  4. how to repeat a simple VBA
    By Katrin84 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-15-2010, 08:15 PM
  5. Replies: 2
    Last Post: 08-24-2005, 12:05 PM

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