Solved

move data from columns to rows - loops

Posted on 2011-02-14
6
205 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
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…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

816 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now