Results 1 to 2 of 2

Copy multiple rows and columns from a workook (Transpose the rows ans multiply by -1)

Threaded View

  1. #1
    Registered User
    Join Date
    09-05-2013
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    4

    Copy multiple rows and columns from a workook (Transpose the rows ans multiply by -1)

    Dear Colleagues,

    I have workbook with many sheets. For each sheet, many rows and columns, I need to copy all rows and columns and transpose them then past in a new workbook. The transposed values are to be multiplied by -1. Then I need to copy and transpose the original cells and past them under the negative values. This means that I have symmetrical values (from negative to positive).

    I used the following code and it works well for all sheets except sheet1, attached Book1. What happened that it multiplies the cells by -1 and misses the last row, sheet Ouputs1 in Book2. I do not know why and I tried my best. I wondering if you could help me sorting this out?

      wb = ActiveWorkbook.name
        Workbooks.Open "C:\Users\Desktop\Test\Book1.xls"
    '#####################################################################################################
        Workbooks("Book1.xls").Activate
        Sheets("Sheet1").Activate
    '
            With ActiveSheet
                    LastRow = .Cells(.Rows.count, "A").End(xlUp).Row
            End With
    '
        i = LastRow
    
    '
            j = 2 * (LastRow - 1) + 8
    '
                For i = 9 To j
                        Range("E9:K" & i).Copy
                Next i
    '
            Windows(wb).Activate
            Sheets("Outputs1").Activate
    '
            Range("A2").PasteSpecial xlPasteAll, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=True
            Application.CutCopyMode = False
            ActiveWorkbook.SaveAs "C:\Users\Desktop\Test\Book2"
    '================ Flip Rows upside down ==============================================================
        Windows(wb).Activate
        Sheets("Outputs1").Activate
    '
        With Selection
            firstRowNum = .Cells(2).Row
            lastRowNum = .Cells(.Cells.count).Row
        End With
    '
        count = 0
        length = (lastRowNum - firstRowNum) / 2
        For thisRowNum = firstRowNum To firstRowNum + length Step 1
            count = count + 1
            lowerRowNum = (lastRowNum - count) + 1
            Set thisCell = Cells(thisRowNum, 1)
            If thisRowNum <> lowerRowNum Then
                thisCell.Select
                ActiveCell.EntireRow.Cut
                Cells(lowerRowNum, 1).EntireRow.Select
                Selection.Insert
                ActiveCell.EntireRow.Cut
                Cells(thisRowNum, 1).Select
                Selection.Insert
            End If
       '
        Next
     '================ Multiply each cell by -1 ==========================================================
                    ActiveSheet.Range("A2").CurrentRegion.Select
                    ActiveSheet.Range("A2", _
                    ActiveSheet.Range("A2").End(xlDown).End(xlToRight)).Select
    '
                   For Each cell In Selection
                          If cell <> "" Then cell = cell * (-1)
                   Next cell
    
    '======= copy sheet1 data and paste them in Outputs1 sheet =============================================
        Workbooks("Book1.xls").Activate
        Sheets("Sheet1").Activate
    '
            j = 2 * (LastRow - 1) + 8
    '
                For i = 9 To j
                    Range("E9:K" & i).Copy
                Next i
    '
            Windows(wb).Activate
            Sheets("Outputs1").Activate
    '
            Range("A9").PasteSpecial xlPasteAll, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=True
            Application.CutCopyMode = False
    Thanks for your time.

    Nawr
    Attached Files Attached Files
    Last edited by alansidman; 01-24-2014 at 06:20 PM. Reason: code tags added

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Transpose Multiple Rows to Columns
    By pjscho in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-09-2013, 10:00 AM
  2. Replies: 5
    Last Post: 05-25-2013, 07:12 AM
  3. Replies: 4
    Last Post: 03-08-2013, 09:49 AM
  4. Transpose every 64 rows into 64 columns with multiple rows
    By owlish in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-09-2012, 06:18 PM
  5. transpose multiple rows and columns
    By prawer in forum Excel General
    Replies: 2
    Last Post: 06-03-2009, 04:20 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1