+ Reply to Thread
Results 1 to 11 of 11

Help with macro shortening

Hybrid View

  1. #1
    Registered User
    Join Date
    11-27-2013
    Location
    Leeds, England
    MS-Off Ver
    Excel 2010
    Posts
    41

    Help with macro shortening

    Hi All,

    I'm working on a little project for a friend and the below macro is one of two macros that are my final sticking points. My Questions with this macro are - can the below be simplified? & I need to repeat this macro to a further 14 times, moving the cell selection down 15 rows each time (with the exception of the final 2 points - inputing day, month, year, input name & changing sheet & saving) - is there an easy way to do this?

    
        Range( _
            "W16:X19,T16:U19,Q16:R19,N16:O19,K16:L19,H16:I19,E16:F19,D10:E10,G10:H10,J10:K10,M10:N10,P10:Q10,S10:T10,V10:W10" _
            ).Select
        Selection.ClearContents
        
        Range("D20:F20").Select
        ActiveCell.FormulaR1C1 = "0"
        Range("D21:F21").Select
        ActiveCell.FormulaR1C1 = "0"
        Range("D22:F22").Select
        ActiveCell.FormulaR1C1 = "0"
        Range("G20:I20").Select
        ActiveCell.FormulaR1C1 = "0"
        Range("G21:I21").Select
        ActiveCell.FormulaR1C1 = "0"
        Range("G22:I22").Select
        ActiveCell.FormulaR1C1 = "0"
        Range("J20:L20").Select
        ActiveCell.FormulaR1C1 = "0"
        Range("J21:L21").Select
        ActiveCell.FormulaR1C1 = "0"
        Range("J22:L22").Select
        ActiveCell.FormulaR1C1 = "0"
        Range("M20:O20").Select
        ActiveCell.FormulaR1C1 = "0"
        Range("M21:O21").Select
        ActiveCell.FormulaR1C1 = "0"
        Range("M22:O22").Select
        ActiveCell.FormulaR1C1 = "0"
        Range("P20:R20").Select
        ActiveCell.FormulaR1C1 = "0"
        Range("P21:R21").Select
        ActiveCell.FormulaR1C1 = "0"
        Range("P22:R22").Select
        ActiveCell.FormulaR1C1 = "0"
        Range("S20:U20").Select
        ActiveCell.FormulaR1C1 = "0"
        Range("S21:U21").Select
        ActiveCell.FormulaR1C1 = "0"
        Range("S22:U22").Select
        ActiveCell.FormulaR1C1 = "0"
        Range("V20:X20").Select
        ActiveCell.FormulaR1C1 = "0"
        Range("V21:X21").Select
        ActiveCell.FormulaR1C1 = "0"
        Range("V22:X22").Select
        ActiveCell.FormulaR1C1 = "0"
        Range("D10:E10").Select
        
        Range("Q5:Q6").Select
        ActiveCell.FormulaR1C1 = "Day"
        Range("R5:T6").Select
        ActiveCell.FormulaR1C1 = "Month"
        Range("U5:U6").Select
        ActiveCell.FormulaR1C1 = "Year"
        Range("AF5:AG6").Select
        ActiveCell.FormulaR1C1 = "INPUT NAME"
        Range("D10:E10").Select
    
        Sheets("Menu").Select
        ActiveWorkbook.Save
    Last edited by M4RSH; 06-12-2014 at 07:10 AM.
    All the Best,

    Marshall

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,037

    Re: Can this Macro be simplified?

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution.

    Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.

    To change a Title on your post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Never use Merged Cells in Excel

  3. #3
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,037

    Re: Can this Macro be simplified?

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

    Posting code between [CODE] [/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 here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

  4. #4
    Registered User
    Join Date
    11-27-2013
    Location
    Leeds, England
    MS-Off Ver
    Excel 2010
    Posts
    41

    Re: Help with macro shortening

    Changed as requested - the original title was my problem - I need to know if I can make the macro simpler.

    Code tags added

  5. #5
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,037

    Re: Help with macro shortening

    Does this help (didn't test)

    Range( _
            "W16:X19,T16:U19,Q16:R19,N16:O19,K16:L19,H16:I19,E16:F19,D10:E10,G10:H10,J10:K10,M10:N10,P10:Q10,S10:T10,V10:W10" _
            ).ClearContents
        
        Range("D20:X2").value = 0
        
        Range("Q5:Q6").value = "Day"
        Range("R5:T6").value = "Month"
        Range("U5:U6").value = "Year"
        Range("AF5:AG6").value = "INPUT NAME"
    
        ActiveWorkbook.Save

  6. #6
    Registered User
    Join Date
    11-27-2013
    Location
    Leeds, England
    MS-Off Ver
    Excel 2010
    Posts
    41

    Re: Help with macro shortening

    This works spot on... slight change of in range for value but perfect - thank you - Zbor.

    Is there a way to duplicate 14 times, moving it on 15 rows at a time?

    Quote Originally Posted by zbor View Post
    Does this help (didn't test)

    Range( _
            "W16:X19,T16:U19,Q16:R19,N16:O19,K16:L19,H16:I19,E16:F19,D10:E10,G10:H10,J10:K10,M10:N10,P10:Q10,S10:T10,V10:W10" _
            ).ClearContents
        
        Range("D20:X22").value = 0
        
        Range("Q5:Q6").value = "Day"
        Range("R5:T6").value = "Month"
        Range("U5:U6").value = "Year"
        Range("AF5:AG6").value = "INPUT NAME"
    
        ActiveWorkbook.Save

  7. #7
    Registered User
    Join Date
    11-27-2013
    Location
    Leeds, England
    MS-Off Ver
    Excel 2010
    Posts
    41

    Re: Help with macro shortening

    Boost..........

  8. #8
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,037

    Re: Help with macro shortening

    Do you mean something like:

    Dim i as integer
    
    For i = 0 to 14
    Range( _
            "W16:X19,T16:U19,Q16:R19,N16:O19,K16:L19,H16:I19,E16:F19,D10:E10,G10:H10,J10:K10,M10:N10,P10:Q10,S10:T10,V10:W10" _
            ).ClearContents
        
        Range("D20:X22").offset(15*i).value = 0
        
        Range("Q5:Q6").offset(15*i).value = "Day"
        Range("R5:T6").offset(15*i).value = "Month"
        Range("U5:U6").offset(15*i).value = "Year"
        Range("AF5:AG6").offset(15*i).value = "INPUT NAME"
    
        ActiveWorkbook.Save
    next i

  9. #9
    Registered User
    Join Date
    11-27-2013
    Location
    Leeds, England
    MS-Off Ver
    Excel 2010
    Posts
    41

    Re: Help with macro shortening

    Thank you Zbor, this is pretty close !!!

    This does do the "zeroing", date & name but with the first range selected to clear contents, I also need that to move down the sheet in the same way.

    Thanks for all your help so far.

  10. #10
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,037

    Re: Help with macro shortening

    Add offset alse there:

    Dim i as integer
    
    For i = 0 to 14
    Range("W16:X19,T16:U19,Q16:R19,N16:O19,K16:L19,H16:I19,E16:F19,D10:E10,G10:H10,J10:K10,M10:N10,P10:Q10,S10:T10,V10:W10").offset(15*i).ClearContents
        
        Range("D20:X22").offset(15*i).value = 0
        
        Range("Q5:Q6").offset(15*i).value = "Day"
        Range("R5:T6").offset(15*i).value = "Month"
        Range("U5:U6").offset(15*i).value = "Year"
        Range("AF5:AG6").offset(15*i).value = "INPUT NAME"
    
        ActiveWorkbook.Save
    next i

  11. #11
    Registered User
    Join Date
    11-27-2013
    Location
    Leeds, England
    MS-Off Ver
    Excel 2010
    Posts
    41

    Re: Help with macro shortening

    This is spot on Zbor,

    Thank you for your help with this.

+ 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. Simplified Macro that copies col A and B from 12 sheets to a Complete sheet
    By programct in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-13-2014, 12:10 PM
  2. [SOLVED] Excel V-Look up Macro Simplified
    By lreed in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-30-2013, 03:59 PM
  3. Simplified Conditional Macro
    By martinez_pedro in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-27-2011, 10:31 PM
  4. Simplified Macro
    By martinez_pedro in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-17-2011, 09:47 AM
  5. Can this be simplified?
    By Niko in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-11-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