+ Reply to Thread
Results 1 to 9 of 9

How to repeat an instruction instead of copying it hundreds of times?

  1. #1
    Registered User
    Join Date
    06-29-2016
    Location
    Ireland
    MS-Off Ver
    2019
    Posts
    47

    How to repeat an instruction instead of copying it hundreds of times?

    Hello guys. My name is Ricardo and I'm totally new to VB.
    I'm trying to convert a cross tab into a flat list like this:

    Please Login or Register  to view this content.
    As I have 140 Cost Centres and 6 Natures I have 840 repetitions and then excluding the zeros.

    My basic skills only allow me to write it manually such as:

    Please Login or Register  to view this content.
    and so on.

    How can I make it more automatic, please?

    Thank you in advance.

    Ricardo
    Last edited by 6StringJazzer; 07-27-2016 at 09:18 AM. Reason: added code tags to data to preserve spacing

  2. #2
    Forum Expert
    Join Date
    09-20-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    2,278

    Re: How to repeat an instruction instead of copying it hundreds of times?

    Hello Ricardo welcome to the forum.

    Take a look at the attached example. Does this do as required?

    DBY
    Attached Files Attached Files

  3. #3
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: How to repeat an instruction instead of copying it hundreds of times?

    Try this:-
    Run code on Data sheet for Results on sheet2
    Please Login or Register  to view this content.
    Regards Mick

  4. #4
    Registered User
    Join Date
    06-29-2016
    Location
    Ireland
    MS-Off Ver
    2019
    Posts
    47

    Re: How to repeat an instruction instead of copying it hundreds of times?

    Dear BDY and MickG.

    Thank you very much for the warm welcoming to the forum. I have to say I never though I would get such a quick reply.
    In a sense, it just made me to feel more insignificant and realize how much I have to learn.

    The 2 ways you showed me are very elegant and work perfectly for the example I gave but because I wasn't too specific (I suppose I can evoke my first timer mistake now),
    I'm having a hard time to adapt it for my needs even having experimented changing the codes many times.

    My cross table is in sheet4 called "CC GA", range D7:J146 (headings not included, just sheer data) where Cost Centres are on column D, and Salary, Fuel, Phone, Vehicle, Petty, Others on columns E to J, respectively.
    I want to transpose the data to sheet10 called "Accounts Export", range C9:E(whatever it takes).

    Could you guys explain to me how to do it in both ways as a matter of education.


    Nice regards,

  5. #5
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: How to repeat an instruction instead of copying it hundreds of times?

    Try this:-
    Please Login or Register  to view this content.
    Regards Mick

  6. #6
    Forum Expert
    Join Date
    09-20-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    2,278

    Re: How to repeat an instruction instead of copying it hundreds of times?

    Here's my code with another example file amended to simulate your description of data.

    DBY
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    06-29-2016
    Location
    Ireland
    MS-Off Ver
    2019
    Posts
    47

    Re: How to repeat an instruction instead of copying it hundreds of times?

    Dear MickG and DBY,
    You guys rock.

    Both ways worked brilliantly and as I actually have two ranges to be copied to the same sheet side by side I'm simply using both codes.
    I only introduced a line to activate the Accounts Export sheet in the beginning of the code as I forgot to say I wanted to execute it from the Accounts Export sheet (no excuses this time),
    another line to unprotect the sheet (this one I decided later) and two more lines before ending the code to activate the Accounts Export sheet again and to protect it again.

    Also, by comparing the latter codes to the ones you sent me previously I was able to understand better how this methods work. Is the case to say that I have a lot to read, I guess...

    Thank you very much,


    Ricardo

  8. #8
    Forum Expert
    Join Date
    09-20-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    2,278

    Re: How to repeat an instruction instead of copying it hundreds of times?

    Glad we could help. Thanks for the rep mark.

  9. #9
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: How to repeat an instruction instead of copying it hundreds of times?

    You're most welcome, Thank you for your reply.

+ 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] Repeat formula X times - once X times has been achieved then Y - repeat X again
    By jonnym28 in forum Excel Formulas & Functions
    Replies: 14
    Last Post: 11-25-2015, 11:53 AM
  2. [SOLVED] repeat cell value x times
    By Julez74 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-29-2015, 08:52 PM
  3. [SOLVED] Repeat number X times
    By mbrandt5 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-29-2015, 05:56 PM
  4. Replies: 4
    Last Post: 03-08-2014, 08:01 AM
  5. Repeat Value X given times
    By rafaelcpaiva in forum Excel General
    Replies: 3
    Last Post: 03-06-2014, 11:03 PM
  6. Transposing a column hundreds of times without doing it manually
    By Mathias8337 in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 12-17-2012, 08:16 AM
  7. How to repeat a macro many times
    By cbo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-07-2010, 05:41 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