MrExcel Message Board


Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Mar 30th, 2004, 04:09 PM   #1
alykat
 
Join Date: Mar 2004
Posts: 7
Default Transpose columns to rows inserting lines & skipping bla

Hi there,

Would anybody be able to help me out with this one:

I have worksheet in which certain rows will need to be transposed into columns. Extra lines containing the information in the first row will need to be inserted, and any blanks skipped.

Let me show you what I mean:

******** ******************** ************************************************************************>
Microsoft Excel - Book1.xls___Running: xl2000 : OS = Windows Windows 2000
(F)ile (E)dit (V)iew (I)nsert (O)ptions (T)ools (D)ata (W)indow (H)elp (A)bout
=

A
B
C
D
E
F
1
What*I*have:*****
2
******
3
NameLocationTransaction*ATransaction*BTransaction*CTransaction*D
4
Mr*JonesLondonABCD
5
Mr*SmithBlackpool*BCD
6
Mrs*RobertsLiverpool**C*
7
Miss*SmithManchesterA*CD
8
******
9
What*I*would*like:*****
10
******
11
NameLocationTransaction***
12
Mr*JonesLondonA***
13
Mr*JonesLondonB***
14
Mr*JonesLondonC***
15
Mr*JonesLondonD***
16
Mr*SmithBlackpoolB***
17
Mr*SmithBlackpoolC***
18
Mr*SmithBlackpoolD***
19
Mrs*RobertsLiverpoolC***
20
Miss*MatthewsManchesterA***
21
Miss*MatthewsManchesterC***
22
Miss*MatthewsManchesterD***
Sheet1*

[HtmlMaker 2.42] To see the formula in the cells just click on the cells hyperlink or click the Name box
PLEASE DO NOT QUOTE THIS TABLE IMAGE ON SAME PAGE! OTHEWISE, ERROR OF JavaScript OCCUR.


Thanks again!
alykat is offline   Reply With Quote
Old Mar 30th, 2004, 04:30 PM   #2
onlyadrafter
 
Join Date: Aug 2003
Location: England
Posts: 4,584
Default Re: Transpose columns to rows inserting lines & skipping

Hello,

Does the following code suit your needs?

Code:
Sub ROWS_TO_COLUMNS()
For MY_ROWS = 1 To Range("A65536").End(xlUp).Row
    MY_NAME = Range("A" & MY_ROWS).Value
    MY_LOCATION = Range("B" & MY_ROWS).Value
    For MY_TR_NO = 3 To 7
        MY_TRANS = Range("A1").Offset(MY_ROWS - 1, MY_TR_NO - 1).Value
    If MY_TRANS <> "" Then
        Range("H65536").End(xlUp).Offset(1, 0) = MY_NAME
        Range("I65536").End(xlUp).Offset(1, 0) = MY_LOCATION
        Range("J65536").End(xlUp).Offset(1, 0) = MY_TRANS
    End If
        MY_TRANS = ""
    Next MY_TR_NO
Next MY_ROWS
End Sub
You will need to change cell refs as required.
__________________
-------------------------
Hope this is helpful.
-------------------------
only a drafter,
but broadening my Excel knowledge.
onlyadrafter is offline   Reply With Quote
Old Mar 31st, 2004, 12:01 PM   #3
alykat
 
Join Date: Mar 2004
Posts: 7
Default Re: Transpose columns to rows inserting lines & skipping

Thanks, that's great.
I've been trying this on another worksheet. Some of the columns work fine, but others are not being copied onto the new lines. Could you let me know what's wrong with the following code?:

Sub ROWS_TO_COLUMNS()
For MY_ROWS = 1 To Range("A65536").End(xlUp).Row
MY_CYBORG_PAY_NO = Range("A" & MY_ROWS).Value
MY_SAP_POSITION_NUMBER = Range("B" & MY_ROWS).Value
MY_NAME = Range("C" & MY_ROWS).Value
MY_SAP_POSITION_TITLE = Range("D" & MY_ROWS).Value
MY_SAP_ORG_UNIT_ID = Range("E" & MY_ROWS).Value
MY_SAP_ORG_UNIT_NAME = Range("F" & MY_ROWS).Value
MY_OBJ_CODE = Range("G" & MY_ROWS).Value
MY_OBJ_DESC = Range("H" & MY_ROWS).Value
MY_FUNCTIONAL_AREA = Range("I" & MY_ROWS).Value
For MY_TR_NO = 10 To 36
MY_TRANS = Range("A1").Offset(MY_ROWS - 1, MY_TR_NO - 1).Value
If MY_TRANS <> "" Then
Range("AL65536").End(xlUp).Offset(1, 0) = MY_CYBORG_PAY_NO
Range("AM65536").End(xlUp).Offset(1, 0) = MY_SAP_POSITION_NUMBER
Range("AN65536").End(xlUp).Offset(1, 0) = MY_NAME
Range("AO65536").End(xlUp).Offset(1, 0) = MY_SAP_POSITION_TITLE
Range("AP65536").End(xlUp).Offset(1, 0) = MY_SAP_ORG_UNIT_ID
Range("AQ65536").End(xlUp).Offset(1, 0) = MY_SAP_ORG_UNIT_NAME
Range("AR65536").End(xlUp).Offset(1, 0) = MY_OBJ_CODE
Range("AS65536").End(xlUp).Offset(1, 0) = MY_OBJ_DESC
Range("AT65536").End(xlUp).Offset(1, 0) = MY_FUNCTIONAL_AREA
Range("AU65536").End(xlUp).Offset(1, 0) = MY_TRANS

End If
MY_TRANS = ""
Next MY_TR_NO
Next MY_ROWS
End Sub


The columns that are not copying correctly are SAP POSITION NUMBER, SAP POSITION TIORG UNIT ID and SAP ORG UNIT NAME.
alykat is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT +1. The time now is 02:44 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
All contents Copyright 1998-2009 by MrExcel Consulting.