Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

move data from columns to rows - loops

Posted on 2011-02-14
6
Medium Priority
?
211 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
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!

 

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 2000 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

Industry Leaders: 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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
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.

688 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