Copy the column cells ("B:N") into the first empty row.

harzer

Board Regular
Joined
Dec 15, 2021
Messages
153
Office Version
  1. 2016
Platform
  1. Windows
Hello everyone,
As I cannot resolve my problem, I am contacting you.
The purpose of my request is to copy the cells of the columns ("B:N") of the Active row to paste them in the first empty row.
Information: We do not take care of column "A" because we only work on columns ("B:N").

To better illustrate my request, we will take an example:
Suppose that I want to copy the cells of the columns ("B:N") of row No. 3, for this, I must select at least one cell in the range ("B3:N3"), so we know how to determine with ( ActiveCell) the line number.
When we know the line number, if we click on a button, we copy all the cells ("B3:N3") in the first empty line, in our case, the first line is line number 5 .

Here is the sheet before executing the code:
Code_Test.xlsm
ABCDEFGHIJKLMN
1JeunePèreMèreEleveurÂgeVolièreCageNé(e)ToursCouleurElevageConsanguinitéancêtre principaleElevage
2Ae27-001/2024 FA1B1C1D1E1F1G1H1I1J1K1L1M1
3Ae27-002/2024 MA2B2C2D2E2F2G2H2I2J2K2L2M2
4Ae27-003/2024 FA3B3C3D3E3F3G3H3I3J3K3L3M3
5Ae27-004/2024 F
6Ae27-005/2024 M
7Ae27-006/2024 M
8Ae27-007/2024 M
9Ae27-008/2024 M
10Ae27-009/2024 M
11Ae27-010/2024 M
12
13
14
15
Parents


Here is the sheet after running the code:
Code_Test.xlsm
ABCDEFGHIJKLMN
1JeunePèreMèreEleveurÂgeVolièreCageNé(e)ToursCouleurElevageConsanguinitéancêtre principaleElevage
2Ae27-001/2024 FA1B1C1D1E1F1G1H1I1J1K1L1M1
3Ae27-002/2024 MA2B2C2D2E2F2G2H2I2J2K2L2M2
4Ae27-003/2024 FA3B3C3D3E3F3G3H3I3J3K3L3M3
5Ae27-004/2024 FA2B2C2D2E2F2G2H2I2J2K2L2M2
6Ae27-005/2024 M
7Ae27-006/2024 M
8Ae27-007/2024 M
9Ae27-008/2024 M
10Ae27-009/2024 M
11Ae27-010/2024 M
12
13
14
15
Parents


Thank you for your contributions.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Copy and paste this macro into the worksheet code module. Do the following: right click the tab name for your "Parents" sheet and click 'View Code'. Paste the macro into the empty code window that opens up. Close the code window to return to your sheet. Double click on any cell in the row that you want to copy.
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Target.CountLarge > 1 Then Exit Sub
    Dim lRow As Long
    lRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    If Target.Row > lRow Or Target.Row = 1 Then Exit Sub
    Application.ScreenUpdating = False
    Range("B" & Target.Row).Resize(, 13).Copy Cells(Rows.Count, "B").End(xlUp).Offset(1)
    Application.ScreenUpdating = True
End Sub
 
Upvote 1
Hello mumps,
Thanks for your feedback.
I tested your code on a sheet that contains no other code except yours, the proposed solution works fine and gives me the correct result.
However, when I put your code in my project in Worksheet_BeforeDoubleClick, the program took a long time to run because in Worksheet_BeforeDoubleClick, I already had other codes running too, hence the slowness.
Could you (please) modify it, so as to link the code to a button so we don't touch the Worksheet_BeforeDoubleClick
Greetings.
 
Upvote 0
Try:
VBA Code:
Sub CopyRange()
    Range("B" & ActiveCell.Row).Resize(, 13).Copy Cells(Rows.Count, "B").End(xlUp).Offset(1)
End Sub
 
Upvote 0
Solution
Hello mumps,
Thank you for your feedback and the proposed code.
The latter works very well.
Plus, a single line of code is magnificent.
Thank you again and we look forward to hearing from you on occasion.
Greetings.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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