Paste to next available ROW

Ace71425

Board Regular
Joined
Apr 20, 2015
Messages
130
I need help! :( .... I have this code that pastes multiple sheets into a master sheet...it works great BUT the code copies the next sheet of data to the next available cell in the A column. This doesn't work for me when there is info in B, C, and D because it cuts that data off. How can I alter this code to look for the next available blank ROW between the range of A-D whereas they are all empty?

Sub runallmacros()

Code:
    Dim wbSource As Workbook
    Dim wsDest As Worksheet
    Dim row As Integer, os As Integer
    
    Set wsDest = ThisWorkbook.Worksheets("File Copier")
    
    row = 2
    os = 0
    
    With wsDest
        Do While .Range("K" & row).Value <> ""
            Set wbSource = Workbooks.Open(wsDest.Range("K" & row).Value)
            wbSource.Worksheets(1).Range("A5:D500").Copy
            Application.DisplayAlerts = False
            wbSource.Close
            Application.DisplayAlerts = True
            If .Range("A1").Value <> "" Then os = 1
            .Range("A" & .Rows.Count).End(xlUp).Offset(os).PasteSpecial
            row = row + 1
        Loop
    End With
    
    Set wbSource = Nothing
    
End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
I need help! :( .... I have this code that pastes multiple sheets into a master sheet...it works great BUT the code copies the next sheet of data to the next available cell in the A column. This doesn't work for me when there is info in B, C, and D because it cuts that data off. How can I alter this code to look for the next available blank ROW between the range of A-D whereas they are all empty?

Sub runallmacros()

Rich (BB code):
    Dim wbSource As Workbook
    Dim wsDest As Worksheet
    Dim row As Integer, os As Integer
    
    Set wsDest = ThisWorkbook.Worksheets("File Copier")
    
    row = 2
    os = 0
    
    With wsDest
        Do While .Range("K" & row).Value <> ""
            Set wbSource = Workbooks.Open(wsDest.Range("K" & row).Value)
            wbSource.Worksheets(1).Range("A5:D500").Copy
            Application.DisplayAlerts = False
            wbSource.Close
            Application.DisplayAlerts = True
            If .Range("A1").Value <> "" Then os = 1
            .Range("A" & .Rows.Count).End(xlUp).Offset(os).PasteSpecial
            row = row + 1
        Loop
    End With
    
    Set wbSource = Nothing
    
End Sub
Try replacing the highlighted line of code with this...
Code:
  .Range("A" & .Columns("A:D").Find(What:="*", SearchOrder:=xlRows, _
    SearchDirection:=xlPrevious, LookIn:=xlValues).Row).Offset(1).PasteSpecial
 
Upvote 0

Forum statistics

Threads
1,215,446
Messages
6,124,900
Members
449,194
Latest member
JayEggleton

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