How I can copy the entire last row to the next row?

Hernan_g_f

New Member
Joined
Jul 26, 2022
Messages
22
Office Version
  1. 365
Platform
  1. Windows
Dear all,

I need to copy the last row of a matrix to the next row. How can I do it?


I wrote the following sentence:

Sub M16b()


Dim wb As Workbook
Set wb = Workbooks("SCDJ Excel VBA.xlsm")

Dim sh As Worksheet
Set sh = wb.Sheets("16b")

Dim rng1 As Range
Set rng1 = sh.Range("B17")

'---------

'2. Insert the last row


rng1.End(xlDown).Select
ActiveCell.EntireRow.Select
Selection.Copy

==> 'I need to copy the last row to the next row (down)

Selection.Paste '(¿?)


End Sub


Thanks in advance!!
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
OK, see if the following gives you what you want:

VBA Code:
Option Explicit
Sub Hernan()
    Dim ws As Worksheet
    Set ws = Workbooks("SCDJ Excel VBA.xlsm").Worksheets("16B")
    Dim LRow As Long, LCol As Long, r As Range
    LRow = ws.Cells(Rows.Count, "B").End(xlUp).Row
    LCol = ws.Rows("17:" & LRow).Find("*", , xlFormulas, , 2, 2).Column
    
    Set r = ws.Range(ws.Cells(LRow, 2), ws.Cells(LRow, LCol))
    r.Offset(1).Value2 = r.Value2
End Sub
 
Upvote 0
Hi Kevin, yes, very helpful, but it's biased. I need that when duplicating the last row, the formulas are also copied

I need to copy the formulas that are into the matrix

Column => A B C

Rows

1 +x1*x1 +x2*x2 +x1*x3
2 + x2*x1 +x2*x2 +x2*x3
3 + x3*x1 +x3*x2 +x3*x

With the code that you wrote me, I can duplicate the row 3, but when I run your VBA code, the new row (4) duplicate the numbers of the third row, but not the formulas

How can I do it? :)

Thanks in Advance!!!
 
Upvote 0
Try this one instead (much easier if you could post a copy of your sheet using the XL2BB - Excel Range to BBCode)

VBA Code:
Option Explicit
Sub henan_V2()
    Dim ws As Worksheet
    Set ws = Workbooks("SCDJ Excel VBA.xlsm").Worksheets("16B")
    Dim LRow As Long, LCol As Long, r As Range
    LRow = ws.Cells(Rows.Count, "B").End(xlUp).Row
    LCol = ws.Rows("17:" & LRow).Find("*", , xlFormulas, , 2, 2).Column
    
    Set r = ws.Range(ws.Cells(LRow, 1), ws.Cells(LRow, LCol))
    r.Copy r.Offset(1)
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,599
Messages
6,120,453
Members
448,967
Latest member
grijken

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top