Solved

move data from columns to rows - loops

Posted on 2011-02-14
6
202 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

757 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

21 Experts available now in Live!

Get 1:1 Help Now