+ Reply to Thread
Results 1 to 4 of 4

Macro to sort data from Table 1 to Table 2 and Three

Hybrid View

  1. #1
    Registered User
    Join Date
    08-24-2015
    Location
    Boston, USA
    MS-Off Ver
    MA
    Posts
    12

    Macro to sort data from Table 1 to Table 2 and Three

    Problem:

    Table 1 Information to be distributed to Table 2 and 3 based on two different criteria.
    Please see the code below for what I'm attempting to do on the attached file.

    1 Sub EWO()
    2 '
    3 ' EWO Macro
    4 '
    5
    6 '
    7 Range("C9:E13").Select
    8 ‘Index rows and columns as j,I variables.
    9 M = COLUMNS = X = (E-(C-1)) = (5-(3-1)) = 3
    10 N = ROWS = Y = (13-(9-1))= 5
    11
    12 ‘For loop around rows and for each in this range assign variables:
    13 For j = 1 to N
    14 YR = Cell(j,M).Value
    15 CO = Cell(j,M+1) .Value
    16 MO = Cell(j,M+2) .Value
    17
    18 ‘Select the range where Table 2 is being set up:
    19 Range("H9:L18").Select
    20 ‘Index this range to access it based on the value of the previous three variables recently created.
    21 COLUMNS2 = TABLE2X = X2 = (L – (H-1)) =
    22 ROWS2 = TABLE2Y = Y2 = (18 – (9-1)) =
    23 ‘Fill in the vectors above with the information regarding the years (or create a mapping to do the job for you J)
    24 ‘Make ActiveCell in Table 2 range equal to the variables recently created:
    25 ActiveCell((Y2 = CO),(X2 = YR)).Value = Value + 1
    26
    27
    28 ‘Select the range where Table 3 is being set up:
    29 Range("H9:L18").Offset(, 6).Select
    30 ‘Again, index this range to access it based on the value of the previous three variables recently created.
    31 COLUMNS3 = TABLE3X = X3 = (N – (R-1)) =
    32 ROWS3 = TABLE3Y = Y3 = (18 – (9-1)) =
    33 ‘Fill in the vectors above with the information regarding the years (or create a mapping to do the job for you J)
    34 ‘Make ActiveCell in Table 3 range equal to the variables recently created:
    35 ActiveCell((Y3 = CO),(X3 = YR)).Value = Value + MO ‘Add variable MO to previous cell value
    36 ‘Repeat the process based on the loop through the rows in the main data
    37 Next
    38
    39 End Sub
    Attached Files Attached Files
    Last edited by anagouveia; 12-13-2015 at 02:28 PM. Reason: DataSort File attached

  2. #2
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    365 Version 2409
    Posts
    2,789

    Re: Macro to sort data from Table 1 to Table 2 and Three

    In the future you should post code without line numbers and use code tags around the code you post so that it looks like this.

    Sub Test()
    End Sub
    It would also be helpful to have a sample file to work with.

    ViewPic

  3. #3
    Registered User
    Join Date
    08-24-2015
    Location
    Boston, USA
    MS-Off Ver
    MA
    Posts
    12

    Re: Macro to sort data from Table 1 to Table 2 and Three

    Any help with this code would be greatly appreciated. Any takers?

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to sort data from Table 1 to Table 2 and Three

    This runs, but what are you trying to do??

    Sub EWO()
    '
    ' EWO Macro
    '
    
    '
        Sheets("Sheet3").Range("C9:E13").Select
    'Index rows and columns as j,i variables.
    'M = Columns = X = (E - (C - 1)) = (5 - (3 - 1)) = 3
    'N = Rows = Y = (13 - (9 - 1)) = 5
    M = 3: N = 5
    'For loop around rows and for each in this range assign variables:
    For j = 9 To 9 + N
    YR = Cells(j, M).Value
    CO = Cells(j, M + 1).Value
    MO = Cells(j, M + 2).Value
    
    'Select the range where Table 2 is being set up:
        Range("H9:L18").Select
    
    
    
    'Fill in the vectors above with the information regarding the years (or create a mapping to do the job for you J)
    
    
    
    
    'Select the range where Table 3 is being set up:
        Range("H9:L18").Offset(, 6).Select
    'Again, index this range to access it based on the value of the previous three variables recently created.
    
    
    'Fill in the vectors above with the information regarding the years (or create a mapping to do the job for you J)
    
    
    'Repeat the process based on the loop through the rows in the main data
    Next
    
    End Sub
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

+ 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. Macro to Copy Pivot Table and Paste a Regular Data Table in the Same Position
    By webfeet2 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-01-2013, 06:34 AM
  2. [SOLVED] Need a formula to sort a table into table (for a Table Plan) and name in column 2
    By jbpianoman in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-07-2012, 09:21 AM
  3. [SOLVED] Macro to list data from a table and sort it alphabetically
    By Siglen in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-16-2012, 11:06 AM
  4. macro to create pivot table(s) and sort out data in other worksheet
    By Astrid in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 12-22-2010, 05:55 PM
  5. Replies: 2
    Last Post: 05-19-2010, 05:14 AM
  6. Replies: 3
    Last Post: 04-15-2009, 11:50 PM
  7. Replies: 1
    Last Post: 09-26-2007, 12:47 AM
  8. Macro that finds word in table and reports all rows with data to new table
    By jermsalerms in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-05-2007, 03:57 AM

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