Copy data from a range and paste it in the next available row in another sheet

brendalpzm

Board Regular
Joined
Oct 3, 2022
Messages
58
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
Platform
  1. Windows
I have a range ("A31:AB31") in the "Input incidents" sheet, so I need to paste it (only values, no formulas) at the next available row in a data base ("Incidents_Accu"),

the columns are also A:AB in the data base, the information should be accumulated in the data base by clicking on an ActiveX Controls Button.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Hi brendalpzm,

Try this:

VBA Code:
Option Explicit
Sub Macro1()

    Dim lngPasteRow As Long
    
    Application.ScreenUpdating = False
    
    With ThisWorkbook
        On Error Resume Next 'Stop the following line producing an error if there's no data on the tab
            lngPasteRow = .Sheets("Incidents_Accu").Range("A:AB").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        On Error GoTo 0
        lngPasteRow = IIf(lngPasteRow = 0, 2, lngPasteRow + 1) 'If the 'lngPasteRow' variable has no value set it 2 (change to suit) or else increment it by 1
        .Sheets("Incidents_Accu").Range("A" & lngPasteRow & ":AB" & lngPasteRow).Value = .Sheets("Input incidents").Range("A31:AB31").Value
    End With
    
    Application.ScreenUpdating = True

End Sub

Regards,

Robert
 
Upvote 1
Solution
Hi brendalpzm,

Try this:

VBA Code:
Option Explicit
Sub Macro1()

    Dim lngPasteRow As Long
   
    Application.ScreenUpdating = False
   
    With ThisWorkbook
        On Error Resume Next 'Stop the following line producing an error if there's no data on the tab
            lngPasteRow = .Sheets("Incidents_Accu").Range("A:AB").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        On Error GoTo 0
        lngPasteRow = IIf(lngPasteRow = 0, 2, lngPasteRow + 1) 'If the 'lngPasteRow' variable has no value set it 2 (change to suit) or else increment it by 1
        .Sheets("Incidents_Accu").Range("A" & lngPasteRow & ":AB" & lngPasteRow).Value = .Sheets("Input incidents").Range("A31:AB31").Value
    End With
   
    Application.ScreenUpdating = True

End Sub

Regards,

Robert
it works! thanks!
 
Upvote 0

Forum statistics

Threads
1,214,987
Messages
6,122,613
Members
449,090
Latest member
vivek chauhan

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