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
Solved

move data from columns to rows - loops

Posted on 2011-02-14
6
206 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
  • 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

808 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