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
Bookmarks