Vb Macro for converting rows into coulmns

Hi Experts--
Can any one plz give me the code to write a VB macro for displaying the input values in the column wise.
By default we are getting the input values in a row between the navigation block and the result area in a report.
My requirement is to display this in the second sheet but column wise.
Any how iam displaying this horizantally (row wise)in the second sheet of a workbook but i need in the column wise.
Thanks & Regards,
Rambo

Hi Rambo,
You can use the following simplified code as a basis for your own.
It takes values in B-column of  RowNo column, parses it and inserts separate values into the 2nd worksheet.
Set value of RowNo and RowNo2 and try it.
Sub SAPBEXonRefresh(queryID As String, resultArea As Range)
Dim ws1 As Worksheet, ws2 As Worksheet, J As Integer
Dim RowNo As Integer, RowNo2 As Integer, CellValue As String, delim As String
Dim StartPos As Integer, EndPos As Integer
RowNo = 6   'Row number with filter values
RowNo2 = 5  'Row number in the 2nd sheet
delim = "," 'Delimiter
Set ws1 = ThisWorkbook.Worksheets("SHEET1")
Set ws2 = ThisWorkbook.Worksheets("SHEET2")
CellValue = ws1.Cells(RowNo, 2)
StartPos = 1
J = 1
Do While J < Len(CellValue)
    If Mid(CellValue, J, 1) = delim Then
        EndPos = J - 1
        ws2.Cells(RowNo2, 1) = Mid(CellValue, StartPos, EndPos - StartPos + 1)
        RowNo2 = RowNo2 + 1
        StartPos = J + 1
    End If
    J = J + 1
Loop
' The last value
ws2.Cells(RowNo2, 1) = Mid(CellValue, EndPos + 2)
End Sub
Best regards,
Eugene

Similar Messages

  • Converting Rows into Column in Oracle 10g

    Hi All,                    
    I m using Oracle Version 10.1.0.2.0 - Production                    
    I have requirement to convert rows into column wise as per the following:                    
    My Query is:                    
    WITH t                    
    AS ( SELECT 'A' AS x, 100 AS y FROM DUAL                     
    UNION ALL                    
    SELECT 'B',200 FROM DUAL                    
    SELECT X, Y                    
    FROM t;     
    X Y
    A 100
    B 200
    My Requirement is
    A B
    100 200
    So any one could help me that how I resolve this.
    Regards,
    Prasanta

    Dear frank,
    Thanks for your support,.
    It's working fine for static cases.If the first column is dynamic then how come i will resolve it.
    Example:
    Create table mytab (ID_C Varchar2(15),Value_N Number);
    Records Population into MyTab table is dynamic.
    Insert into mytab values('HO',5000);
    Insert Into mytab values('PG1',2400);
    Insert Into mytab values('PG2',3000);
    Insert Into mytab values('PG3',800);
    Commit;
    SQL> Select * From MyTab;
    IDC_ ValueN_
    HO 5000
    PG1 2400
    PG2 3000
    PG3 800
    Then My expected result will be as follows
    HO PG1 PG2 PG3
    5000 2400 3000 800
    Thanks and Regards,
    Prasanta

  • CONVERT ROWS INTO COLUMNS IN INTERNAL TABLE

    Hi Experts,
    I want to convert rows into coloumns in final internal table.
    How to do that one. Can any one help me its very urgent.
    Regards,
    PBS.

    hi,
    Find the below code for changing rows into colums.
    data: begin of itab1 occurs 0,
    fld,
    end of itab1.
    data: begin of itab2 occurs 0,
    fld1,
    fld2,
    fld3,
    end of itab2.
    itab1-fld = 1.
    append itab1.
    itab1-fld = 2.
    append itab1.
    itab1-fld = 3.
    append itab1.
    read table itab1 index 1.
    if sy-subrc eq 0.
    itab2-fld1 = itab1-fld.
    endif.
    read table itab1 index 2.
    if sy-subrc eq 0.
    itab2-fld2 = itab1-fld.
    endif.
    read table itab1 index 3.
    if sy-subrc eq 0.
    itab2-fld3 = itab1-fld.
    endif.
    append itab2.
    loop at itab1.
    write:/ itab1.
    endloop.
    loop at itab2.
    write:/ itab2.
    endloop.
    refer the below link for further information
    internal table rows to columns
    in the final display list how can i change rows to columns and vice versa

  • Convert rows into columns nad vice versa in 10g

    how to convert rows into columns in 10g??

    Qwerty wrote:
    see below for rows to column case
    SQL> WITH t as
    2      (
    3       SELECT 'US' test_string FROM DUAL UNION
    4       SELECT 'AMERICA'  FROM DUAL UNION
    5       SELECT'HOLLYWOOD'  FROM DUAL UNION
    6       SELECT 'WASHINGTON'  FROM DUAL
    7      )
    8      select ltrim (sys_connect_by_path(test_string,','),',') test_string
    9        from (
    10     SELECT row_number() over(order by test_string) rno, test_string
    11       FROM t)
    12       WHERE connect_by_isleaf = 1 and rownum=1
    13       connect by rno = prior rno+1;
    TEST_STRING
    AMERICA,HOLLYWOOD,US,WASHINGTONI hope you can do it for column to rows now.That's not really rows to columns. That's rows to a column, which is more commonly called string aggregation.
    Rows to columns (or pivot) is more like:
    SQL> ed
    Wrote file afiedt.buf
      1  WITH t as
      2       (
      3        SELECT 'US' test_string FROM DUAL UNION
      4        SELECT 'AMERICA'  FROM DUAL UNION
      5        SELECT'HOLLYWOOD'  FROM DUAL UNION
      6        SELECT 'WASHINGTON'  FROM DUAL
      7       )
      8  --
      9  select max(decode(rn,1,test_string)) as col_1
    10        ,max(decode(rn,2,test_string)) as col_2
    11        ,max(decode(rn,3,test_string)) as col_3
    12        ,max(decode(rn,4,test_string)) as col_4
    13* from (select test_string, row_number() over (order by test_string) as rn from t)
    SQL> /
    COL_1      COL_2      COL_3      COL_4
    AMERICA    HOLLYWOOD  US         WASHINGTON
    SQL>And columns to rows (or unpivot) is like:
    SQL> ed
    Wrote file afiedt.buf
      1  WITH t as
      2       (
      3        SELECT 'US' col_1, 'AMERICA' col_2, 'HOLLYWOOD' col_3, 'WASHINGTON' col_4 FROM DUAL
      4       )
      5  --
      6  select col_1 as col from t union all
      7  select col_2 from t union all
      8  select col_3 from t union all
      9* select col_4 from t
    SQL> /
    COL
    US
    AMERICA
    HOLLYWOOD
    WASHINGTONor...
    SQL> ed
    Wrote file afiedt.buf
      1  WITH t as
      2       (
      3        SELECT 'US' col_1, 'AMERICA' col_2, 'HOLLYWOOD' col_3, 'WASHINGTON' col_4 FROM DUAL
      4       )
      5  --
      6  select decode(rownum,1,col_1,2,col_2,3,col_3,4,col_4) as col
      7* from t, (select * from dual connect by rownum <= 4)
    SQL> /
    COL
    US
    AMERICA
    HOLLYWOOD
    WASHINGTON
    SQL>

  • How to convert row into column

    Hi All,
    My oracle apps version is r12 and db is 10 and i am using Bi publisher version 10g.
    Is it possible to convert row into column in Rtf template,
    My Query is
    SELECT distinct pvs.vendor_site_code,sum(aia.invoice_amount)
    FROM ap_invoices_all aia, po_vendors po, po_vendor_sites_all pvs
    WHERE aia.org_id = pvs.org_id
    AND aia.vendor_id = po.vendor_id
    AND aia.vendor_site_id = pvs.vendor_site_id
    AND aia.org_id=204
    group by pvs.vendor_site_code
    And output is like this
    Vendor sitecode Invoiceamt
    EAM-ERS 79240
    STAR GATE - PAY 3245902.31
    UPS - HQ 10792040.9
    Like this
    So in template i need the output like this
    Vendor sitecode EAM-ERS STAR GATE - PAY UPS - HQ
    Invoiceamt 79240 3245902.31 10792040.9
    I tried to achieve the output using sql query but by hardcoding only i have achieved it, so i have tried to convert directly in RTF template.
    can any one tell me is it possible.
    And if new project is added from the front end ie(now the query will produce 4 rows but now in template i have created only three columns)
    Is it possible to add a new column dynamically.
    Can any one please guide me and tell me is there any example.
    Thanks & regards
    Srikkanth

    Take a look at this post: http://blogs.oracle.com/roller-ui/bsc/spider.jsp?entry=MT%3aENTRY%3a5001
    Thanks,
    Bipuser

  • How to convert rows into columns with decode function

    Hi,
    How to convert rows into columns with the help of decode function in oracle.
    thanks and regards
    P Prakash

    say
    col1 col2
    1 10
    2 20
    3 30
    then use
    select col1,
    sum(decode(col2,10,10)) "new1"
    sum(decode(col2,20,20))"new2"
    sum(decode(col2,30,30))"new3"
    from table_name
    group by col1;
    we used sum u can use ny function if wont u have to give the column name i.e col2 name also
    so i think u got it nw
    regards

  • What is the t.code for convert Idoc into XML schema

    Hi all,
       How to convert IDOC as XML schema?
    there is one T.code is there for convert IDOC into Xml schem ,I  forgot that,
    plz tell me if anybody knows that t.code. Very Urgent
    Thanks in Advance
    rambabu.A

    WE60
    Let me know if you need any other help with that.
    Best Regards,
    Steve Hardeman

  • How to convert rows into column

    Hi,
    can any one help me how to convert rows into column by pl/sql procedure.
    Thanks and Regards

    http://www.oracle.com/technology/oramag/code/tips2004/050304.html
    -- dropping the sample table if exists
    drop table rowstocol
    -- create sample table
    create table rowstocol ( name varchar2(20));
    -- Inserting rows into sample table
    insert into rowstocol values('Amit Zhankar');
    insert into rowstocol values('Piyu Yawalkar');
    insert into rowstocol values('Piyu Yawalkar');
    insert into rowstocol values('Ashish Ghelani');
    insert into rowstocol values('Aditi Zhankar');
    insert into rowstocol values('Tom Kyte');
    insert into rowstocol values('Oracle');
    -- Following query should be run to create a sql. This result sql should be run to convert rows to column.
    -- The following query uses just the tablename (whose data is to be converted) and name of the column (which is to be converted).
    -- Example taken here is table rowstocol, column name.
    SELECT cc
    FROM (select decode(rn ,1 ,'Select ',null) ||' MAX (CASE WHEN dr = '|| rownum||' THEN DECODE (rn,1, col1) END) '||
    decode(rn,maxr,' col1 from ','||'||chr(39)||','||chr(39)||'|| ') cc,rn,maxr
    from (SELECT ROWNUM rn,count(0) over() maxr FROM rowstocol) order by rn) trows
    union all
    select '(SELECT tabs.col1, DENSE_RANK () OVER (ORDER BY col1,rowid) dr,dense_rank() OVER (order by 1) rn
    FROM (SELECT NAME col1 FROM rowstocol) tabs ) group by rn' cc from dual;
    -- The result of this query will do the reqd conversion from row to column.
    -- Replace table rowstocol by your table, column name by your column.
    CC
    Select MAX (CASE WHEN dr = 1 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 2 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 3 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 4 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 5 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 6 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 7 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 8 THEN DECODE (rn,1, col1) END) col1 from
    (SELECT tabs.col1, DENSE_RANK () OVER (ORDER BY col1,rowid) dr,dense_rank() OVER (order by 1) rn
    FROM (SELECT NAME col1 FROM rowstocol) tabs ) group by rn
    Select MAX (CASE WHEN dr = 1 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 2 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 3 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 4 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 5 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 6 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 7 THEN DECODE (rn,1, col1) END) ||','||
    MAX (CASE WHEN dr = 8 THEN DECODE (rn,1, col1) END) col1 from
    (SELECT tabs.col1, DENSE_RANK () OVER (ORDER BY col1,rowid) dr,dense_rank() OVER (order by 1) rn
    FROM (SELECT NAME col1 FROM rowstocol) tabs ) group by rn;
    COL1
    Aditi Zhankar,Amit Zhankar,Ashish Ghelani,Oracle,Oracle,Piyu Yawalkar,Piyu Yawalkar,Tom Kyte
    Edited by: bhooma on Jan 20, 2009 2:44 AM

  • How to convert rows into columns

    Hi,
    How to convert rows into columns of two different tables.
    These two tables have two common columns namely (shipline,pos).
    Let me know if we have any built in functions to do this.
    thank you very much .
    Edited by: 808542 on Dec 7, 2010 8:35 PM
    Edited by: 808542 on Dec 7, 2010 8:37 PM

    Have you tried this first?
    http://forums.oracle.com/forums/search.jspa?threadID=&q=row+to+column&objID=f75&dateRange=last90days&userID=&numResults=15&rankBy=10001

  • CONVERTING ROWS INTO COLUMNS

    Hi,
    create table this_will_be_ugly (column1 number, column2 varchar2(2), column3 number, column4 number);
    insert into this_will_be_ugly values (1, 'MA', 100, 10000);
    insert into this_will_be_ugly values (2, 'MA', 102, 10001);
    insert into this_will_be_ugly values (3, 'MB', 100, 10001);
    insert into this_will_be_ugly values (4, 'MC', 200, 10001);
    insert into this_will_be_ugly values (5, 'MB', 220, 10003);
    insert into this_will_be_ugly values (6, 'MA', 103, 10004);
    COMMIT;
    CREATE OR REPLACE FUNCTION RET_CROSS_TAN RETURN SYS_REFCURSOR IS
    CURSOR CUR_DIST IS SELECT DISTINCT COLUMN2 FROM this_will_be_ugly;
    V_SELECT VARCHAR2(30);
    V_SELECT1 VARCHAR2(3000);
    v_final varchar2(3500);
    type ref_cur is ref cursor;
    v_ref ref_cur;
    BEGIN
    OPEN CUR_DIST;
    FETCH CUR_DIST INTO V_SELECT;
    LOOP
    IF CUR_DIST%NOTFOUND THEN
    V_SELECT1 := SUBSTR(V_SELECT1,1,LENGTH(V_SELECT1)-1);
    EXIT;
    END IF;
    V_SELECT1 := V_SELECT1||''''||V_SELECT ||''',';
    fetch cur_dist into v_select;
    END LOOP;
    CLOSE CUR_DIST;
    v_final := 'WITH PIVOT_DATA AS (select COLUMN2,COLUMN4 AS DATA,COLUMN3 from this_will_be_ugly GROUP BY COLUMN2,COLUMN3,COLUMN4)
    SELECT * FROM PIVOT_DATA PIVOT ( MIN(COLUMN3)
    FOR COLUMN2 IN ('|| V_SELECT1||'))';
    open v_ref for v_final;
    return v_ref;                                        
    END;
    I written this function to form the query which gives the pivot results.
    May i know is there any way to write the query directly instead of this function?

    Hi,
    If you want the number of columns in the output to depend on the data in the table, then you have to use dynamic SQL, more or less like you did. The number of columns in a query has to be specified when the query is compiled. You can't compile something today that figures out how many distinct values you will have, and therefore how many columns you will need, tomorrow or next month.
    See the following thread for several ways to deal with a dynamic numebr of columns
    Re: Report count and sum from many rows into many columns
    String aggregation is especially useful.

  • What is a good app to use for converting lps into iTunes

    What is a good app for converting lps (albums) into iTunes?

    I know. I did that before i received your reply and I just purchased VinylStudio. Thanks.

  • Convert row into column

    I have table having below records.
    empno ename deptno
    101 a 10
    102 b 20
    103 c 10
    104 d 20
    105 e 30
    Normal Output using Group by.
    deptno count(*)
    10 2
    20 2
    30 1
    I want to display like below(rows into columns)
    Requiredl Output
    10 20 30
    2 2 1
    Deptnos are in first row and cout of deptno nos are second row.

    Check out this thread from the FAQ: {message:id=9360005}

  • Convert Rows  into single column

    Hi,
    My employee details table has data like below,
    employee_id position department
    100 technician 50
    100 IT 80
    101 Accountant 60
    101 Accounting Manager 70
    Now i want to covert the rows into column. So my output should be like this.
    output:
    employee_id position department position1 department1
    100 technician 50 IT 80
    101 Accountant 60 Accounting Manager 70
    Help me on this
    Edited by: Vi on Mar 22, 2012 5:36 AM
    Edited by: Vi on Mar 22, 2012 5:36 AM

    Igor.M wrote:
    http:// website link removed /t_converting_rows_columns.htm
    Please don't post links to commercial websites that are only trying to sell their products and services. It breaches the terms of use of the forums.
    There are usually more suitable websites giving much more valuable information without all the self promotion (google adwords etc. are acceptable), or in the case of this particular question there is a FAQ post that relates to it...
    {message:id=9360005}

  • Convert row into columns

    Hello World ,
    I want to make the below table data come in one row
    Name | code | MARK
    AAA | CODE2 | 50
    AAA | CODE1 | 30
    AAA | CODE3 | 22
    BBB | CODE2 | 52
    BBB | CODE3 | 53
    CCC | CODE3 | 11
    AES | CODE1 | 75
    FES | CODE2 | 44
    i want it to be like this
    NAME | CODE1 | CODE2 | CODE3
    AAA | 30 | 30 | 22
    BBB | - | 52 | 53
    CCC | - | - | 11
    is there another way of DECODE?
    Regards

    A very small amount of effort on your side would have found the FAQ thread "How do I convert rows to columns" SQL and PL/SQL FAQ

  • Converting row into column for work area.

    Hi,
    I have a very simple requirement.
    Let we have a work area <WA> with fields F1, F2 and F3 and corresponding value as V1, V2 and V3 respectively. WA-F1 = V1,WA-F2 = V2, WA-F3 = V3 .
    F1  F2 F3
    V1  V2 V3
    Now my requirement is I want this field name and value as entry of new internal table with three entries, like shown below.
    F   V ( F and V are field name of new internal table)
    F1  V1
    F2  V2
    F3  V3
    So our new table have three entries now.
    One way have done is, as I know the field name so i read its value and append them one by one in new table, but it doesn't seem good and time consuming if number of fields are quite large let say 50. Then we have to append 50 times.
    Do some one have other way to do this, any function module,class or any new logic.
    Thanks in advance.
    Hemant.

    Hi hemant,
    Use method cl_alv_table_create=>create_dynamic_table to get dynamic internal table, using that we can get ouput in the above said format in ALV.
    Example:
    Say your internal table is declared like
    matnr     type mara-matnr,
    code     type wgh01-wwgha,
    desc     type wgh01-wwghb,
    qty       type mseg-menge,
    sample output:
    matnr--desc1desc2--
    desc3
    12354--34--
    10
    1234 is material and 3;4;10 are respective quantity
    Ur field catelog will be:
      lcat-fieldname = 'HEAD'.
      lcat-datatype = 'CHAR'.
      lcat-seltext = 'Category'.
      lcat-intlen = 128.
      lcat-outputlen = 50.
      append lcat to fieldcat.
      clear lcat.
      lcat-fieldname = 'MATNR'.
      lcat-datatype = 'CHAR'.
      lcat-seltext = 'matnr'.
      lcat-intlen = 4.
      lcat-outputlen = 50.
      append lcat to fieldcat.
      clear lcat.
    Dynamic fields:
      loop at it_final into wa_final.
        read table fieldcat into lcat with key fieldname = wa_final-code.
        if sy-subrc <> 0.
          lcat-fieldname = wa_final-code.
          lcat-datatype = 'CHAR'.
          lcat-seltext = wa_final-desc.
          lcat-intlen = 17.
          append lcat to fieldcat.
          clear lcat.
        endif.
      endloop.
      call method cl_alv_table_create=>create_dynamic_table
        exporting
         i_style_table             =
          it_fieldcatalog           = fieldcat
         i_length_in_byte          =
        importing
          ep_table                  = newfield
         e_style_fname             =
       exceptions
         generate_subpool_dir_full = 1
         others                    = 2
      if sy-subrc <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      endif.
      assign newfield->* to <dynamic_cat>.
      create data newdata like line of <dynamic_cat>.
      assign newdata->* to <dynamic_value>.
    endform.                    " buildcat
    populate value to the dynamic internal table********
    form loadata .
      loop at it_final into wa_final.
        assign component 'HEAD' of structure <dynamic_value> to <fs1>.
        <fs1> = wa_final-head.
        assign component 'MATNR' of structure <dynamic_value> to <fs1>.
        <fs1> = ' '.
        assign component wa_final-code of structure <dynamic_value> to <fs1>.
        <fs1> = wa_final-qty.
        at end of head.
          append <dynamic_value> to <dynamic_cat>.
          clear : <dynamic_value>.
        endat.
        clear : wa_final.
      endloop.
    You have to pass <dynamic_cat> table in the ALV Grid display function module.
    Regards,
    Aswin.

Maybe you are looking for