Results 1 to 9 of 9

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

Threaded View

  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:

    From:
    CC   Salary   Fuel    Phone    Vehicle    Petty    
    1      1000    50        10          0       70
    2      1500    60        15        180        0    
    3      3000    70        20          0      100
    
    To:
    CC     Nature     Amount
    1      Salary     1000
    2      Salary     1500
    3      Salary     3000
    1      Fuel         50
    2      Fuel         60
    3      Fuel         70
    1      Phone        10
    2      Phone        15
    3      Phone        20  
    2      Vehicle     180
    1      Petty        70
    3      Petty       100
    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:

    Sub AEGA()
    
        Sheets("CC GA").Select
        Range("D7").Select
        Selection.Copy
        Sheets("Accounts Export").Select
        Range("C9").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Sheets("CC GA").Select
        Range("E6").Select
        Application.CutCopyMode = False
        Selection.Copy
        Sheets("Accounts Export").Select
        Range("D9").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Sheets("CC GA").Select
        Range("E7").Select
        Application.CutCopyMode = False
        Selection.Copy
        Sheets("Accounts Export").Select
        Range("E9").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
            
        Sheets("CC GA").Select
        Range("D8").Select
        Selection.Copy
        Sheets("Accounts Export").Select
        Range("C10").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Sheets("CC GA").Select
        Range("E6").Select
        Application.CutCopyMode = False
        Selection.Copy
        Sheets("Accounts Export").Select
        Range("D10").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Sheets("CC GA").Select
        Range("E8").Select
        Application.CutCopyMode = False
        Selection.Copy
        Sheets("Accounts Export").Select
        Range("E10").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
    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

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