Hi all,
I recently discovered this site as I am learning more about excel. Hope you can help me with my problem.
I currently have a spreadsheet with 26 columns and 3849 columns.
I am trying to insert two rows in between each of the current rows. After that I want to move the data from O3 to C4 and then c5=C3-C4. I already have some of the code but for some reason it only inserts one row in between each of the current rows and it doesn't loop. I had a friend right this code so i have no idea how this works.
Below is the code that will insert one row between each row and will copy the correct cells to where i want them, and it will also do the subtraction.
I need to make it so it inserts two rows. Please help!
Sub addrow()
LastRow = Application.WorksheetFunction.CountA(Range("A:A")
Application.ScreenUpdating = False
For x = 0 To LastRow
ThisWorkbook.Worksheets("Sheet6".Range("C4".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("O3".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("A4".Offset(x + 2 * x, 0).EntireRow.Insert
ThisWorkbook.Worksheets("Sheet6".Range("C4".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("O3".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("D4".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("P3".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("E4".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("Q3".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("F4".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("R3".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("G4".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("S3".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("H4".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("T3".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("I4".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("U3".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("J4".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("V3".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("K4".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("W3".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("L4".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("X3".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("M4".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("Y3".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("N4".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("Z3".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("C5".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("C3".Offset(x + 2 * x, 0) - ThisWorkbook.Worksheets("Sheet6".Range("C4".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("D5".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("D3".Offset(x + 2 * x, 0) - ThisWorkbook.Worksheets("Sheet6".Range("D4".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("E5".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("E3".Offset(x + 2 * x, 0) - ThisWorkbook.Worksheets("Sheet6".Range("E4".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("F5".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("F3".Offset(x + 2 * x, 0) - ThisWorkbook.Worksheets("Sheet6".Range("F4".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("G5".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("G3".Offset(x + 2 * x, 0) - ThisWorkbook.Worksheets("Sheet6".Range("G4".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("H5".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("H3".Offset(x + 2 * x, 0) - ThisWorkbook.Worksheets("Sheet6".Range("H4".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("I5".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("I3".Offset(x + 2 * x, 0) - ThisWorkbook.Worksheets("Sheet6".Range("I4".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("J5".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("J3".Offset(x + 2 * x, 0) - ThisWorkbook.Worksheets("Sheet6".Range("J4".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("K5".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("K3".Offset(x + 2 * x, 0) - ThisWorkbook.Worksheets("Sheet6".Range("K4".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("L5".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("L3".Offset(x + 2 * x, 0) - ThisWorkbook.Worksheets("Sheet6".Range("L4".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("M5".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("M3".Offset(x + 2 * x, 0) - ThisWorkbook.Worksheets("Sheet6".Range("M4".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("N5".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("N3".Offset(x + 2 * x, 0) - ThisWorkbook.Worksheets("Sheet6".Range("N4".Offset(x + 2 * x, 0)
Next x
End Sub
I recently discovered this site as I am learning more about excel. Hope you can help me with my problem.
I currently have a spreadsheet with 26 columns and 3849 columns.
I am trying to insert two rows in between each of the current rows. After that I want to move the data from O3 to C4 and then c5=C3-C4. I already have some of the code but for some reason it only inserts one row in between each of the current rows and it doesn't loop. I had a friend right this code so i have no idea how this works.
Below is the code that will insert one row between each row and will copy the correct cells to where i want them, and it will also do the subtraction.
I need to make it so it inserts two rows. Please help!
Sub addrow()
LastRow = Application.WorksheetFunction.CountA(Range("A:A")
Application.ScreenUpdating = False
For x = 0 To LastRow
ThisWorkbook.Worksheets("Sheet6".Range("C4".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("O3".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("A4".Offset(x + 2 * x, 0).EntireRow.Insert
ThisWorkbook.Worksheets("Sheet6".Range("C4".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("O3".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("D4".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("P3".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("E4".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("Q3".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("F4".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("R3".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("G4".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("S3".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("H4".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("T3".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("I4".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("U3".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("J4".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("V3".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("K4".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("W3".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("L4".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("X3".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("M4".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("Y3".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("N4".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("Z3".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("C5".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("C3".Offset(x + 2 * x, 0) - ThisWorkbook.Worksheets("Sheet6".Range("C4".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("D5".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("D3".Offset(x + 2 * x, 0) - ThisWorkbook.Worksheets("Sheet6".Range("D4".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("E5".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("E3".Offset(x + 2 * x, 0) - ThisWorkbook.Worksheets("Sheet6".Range("E4".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("F5".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("F3".Offset(x + 2 * x, 0) - ThisWorkbook.Worksheets("Sheet6".Range("F4".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("G5".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("G3".Offset(x + 2 * x, 0) - ThisWorkbook.Worksheets("Sheet6".Range("G4".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("H5".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("H3".Offset(x + 2 * x, 0) - ThisWorkbook.Worksheets("Sheet6".Range("H4".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("I5".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("I3".Offset(x + 2 * x, 0) - ThisWorkbook.Worksheets("Sheet6".Range("I4".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("J5".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("J3".Offset(x + 2 * x, 0) - ThisWorkbook.Worksheets("Sheet6".Range("J4".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("K5".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("K3".Offset(x + 2 * x, 0) - ThisWorkbook.Worksheets("Sheet6".Range("K4".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("L5".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("L3".Offset(x + 2 * x, 0) - ThisWorkbook.Worksheets("Sheet6".Range("L4".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("M5".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("M3".Offset(x + 2 * x, 0) - ThisWorkbook.Worksheets("Sheet6".Range("M4".Offset(x + 2 * x, 0)
ThisWorkbook.Worksheets("Sheet6".Range("N5".Offset(x + 2 * x, 0) = ThisWorkbook.Worksheets("Sheet6".Range("N3".Offset(x + 2 * x, 0) - ThisWorkbook.Worksheets("Sheet6".Range("N4".Offset(x + 2 * x, 0)
Next x
End Sub