paste to the next available row

Rubber Beaked Woodpecker

Board Regular
Joined
Aug 30, 2015
Messages
205
Office Version
  1. 2021
Hi guys :)

I use the following code which works very well.

VBA Code:
Sub RS()
   
Dim source As Worksheet
Dim destination As Worksheet
Dim emptyColumn As Long

Set source = Sheets("Sheet1")
Set destination = Sheets("Sheet8")

source.Range("Z2:Z38").Copy 

emptyColumn = destination.Cells(28, destination.Columns.Count).End(xlToLeft).Column

If IsEmpty(destination.Range("A28")) Then
    destination.Cells(1, 1).PasteSpecial Transpose:=True
       
Else
    emptyColumn = emptyColumn + 1
    destination.Cells(28, emptyColumn).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        
        
  destination.Cells(28, emptyColumn).PasteSpecial Paste:=xlPasteFormats
  
Sheets("Sheet8").Select
         ActiveSheet.Calculate
        
    
End If
   
End Sub

However I would also now like the macro to perform the following after the original code has been executed.

Copy Sheet1 AA4:AB4

and paste to the next available row on Sheet8 starting at A250.

The next time the macro is run is will again copy Sheet1 AA4:AB4 and paste to the next available row on Sheet8 which will be A251
The next time the macro is run is will again copy Sheet1 AA4:AB4 and paste to the next available row on Sheet8 which will be A252
The next time the macro is run is will again copy Sheet1 AA4:AB4 and paste to the next available row on Sheet8 which will be A253... and so on

Any advice on this please.

Many thanks

RBW
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hi RBW,

Here's one way:

VBA Code:
Option Explicit
Sub Macro1()

    Dim lngPasteRow As Long
    
    Application.ScreenUpdating = False
    
    With ThisWorkbook
        lngPasteRow = .Sheets("Sheet8").Cells(Rows.Count, "A").End(xlUp).Row + 1
        lngPasteRow = IIf(lngPasteRow < 250, 250, lngPasteRow)
        .Sheets("Sheet1").Range("AA4:AB4").Copy Destination:=.Sheets("Sheet8").Range("A" & lngPasteRow)
    End With
    
    Application.ScreenUpdating = True
    
End Sub

Regards,

Robert
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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