Solved

move data from columns to rows - loops

Posted on 2011-02-14
6
207 Views
Last Modified: 2012-05-11
Thats the continuation of the question: http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_26783239.html

So:
Is there any way to loop it for many columns and rows?

Book1.xls
0
Comment
Question by:yahoo800
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 7

Expert Comment

by:kemi67
ID: 34887474
Can you post  a sample file?
From your previous example it is not clear how many rows and columns you need.
It is not clear how to check where the data rows end and where the selection rows begin.
Are you sure that you are using the correct approach to your problem?
Perhaps we can help for the solution if we know even the original problem, that is whydo you want select the rows in that strange way.
0
 
LVL 7

Expert Comment

by:kemi67
ID: 34887742
I am sorry, now i see the attached file.
But it seems different from the first question.
Can you please write what do you expect as result, since the selection in book1.xls?
0
 

Author Comment

by:yahoo800
ID: 34887974
thats the desired output
I slightly changed the table from example in book1
cheers
Book2.xls
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:yahoo800
ID: 34888030
i have lots of files like this and each of them contains more than hundred columns. It would be nice to automate it so that it reckognize nr of rows/columns ie len>1
0
 
LVL 7

Accepted Solution

by:
kemi67 earned 500 total points
ID: 34889102
I am including the modified book1
Here is the modified function
The output is slighlty different from your book2 because you have selected something the columns that cointains a b c d e (rows 11 and 14)
The output is on Sheet2

 
Public Sub CommandButton1_Click()

    Dim I As Long, lastrow As Long
        Dim t As Long
    Dim h As Long
    Dim nr As Long
    Dim lastcol As Long
    Dim firstSelectionRow As Long
    Dim firstDataCol As Long
    Dim outputLastRow As Long
    Dim outputSheet As String
    
    
    
    outputSheet = "Sheet2"
    
    
    
    lastrow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
    lastcol = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
    For I = 1 To lastrow
       If Cells(I, 1) <> "" Then
          firstSelectionRow = I + 1
          Exit For
       End If
    Next
    For I = 1 To lastcol
       If Cells(1, I) <> "" Then
          firstDataCol = I
          Exit For
       End If
    Next
    
    outputLastRow = 1
   
    For I = firstSelectionRow To lastrow
        For h = 1 To firstDataCol - 1
           Sheets(outputSheet).Cells(outputLastRow, h).Value = Cells(I, h).Value
        Next
        For t = firstDataCol To lastcol
            If UCase(Cells(I, t).Value) = "X" Then
                For nr = 1 To firstSelectionRow - 2
                    Sheets(outputSheet).Cells(outputLastRow, nr + firstDataCol - 1) = Cells(nr, t).Value
                Next
                outputLastRow = outputLastRow + 1
            End If
        Next
    Next I

End Sub

Open in new window

Book1.xls
0
 

Author Comment

by:yahoo800
ID: 34895338
if u email me on weeerty at poczta.onet.pl ill email u back the oryginal file as there are still some minor things which I cant sort out (eg it copies only data from first and second cell of every column)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question