Copy and Paste Between Workbooks with Dynamic Ranges

reberryjr

Well-known Member
Joined
Mar 16, 2017
Messages
701
Office Version
  1. 365
Platform
  1. Windows
I don't know why I'm struggling with this, but I am. I'm trying to paste the value of 1 cell from workbook A into the first empty cell of column B in workbook X all the way until the last cell in column Q of workbook X.

VBA Code:
Dim mLR, sLR, aLR As Long

Set m = ThisWorkbook
Set mA = m.Sheets("ALM_Data_Upload")

mLR = mA.Range("A" & Rows.Count).End(xlUp).Row

'Opens file picker and sets the chosen file as "s" for future coding reference.
With Application.FileDialog(3)
    .AllowMultiSelect = False
    If .Show Then
        fullpath = .SelectedItems.Item(1)
        Set s = Workbooks.Open(fullpath)
    End If

    'Exits the sub if no file is chosen.
    If s Is Nothing Then Exit Sub
    
    Set sS = s.Worksheets(1)
    
    sLR = sS.Range("L" & Rows.Count).End(xlUp).Row
    
    'Copies the Step Number, Description and Expectation from the actual script and pastes it into the ALM Upload tab.
    sS.Range("A11:C11" & sLR).Copy
        mA.Range("L" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
        
    aLR = sS.Range("L" & Rows.Count).End(xlUp).Row
    
    'Copies the Test Name from the actual script and pastes it into the ALM Upload tab.
    sS.Range("B1").Copy
       mA.range("B" & sLR+1  ":B" & aLR).pastespecial xlpastevalues
        'mA.Range("B" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,215,067
Messages
6,122,949
Members
449,095
Latest member
nmaske

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